This commit is contained in:
cangui 2025-08-18 20:39:25 +02:00
parent e60adf921b
commit 88c2e12b14

33
main.go
View File

@ -12,10 +12,8 @@ import (
"encoding/pem"
"fmt"
"io"
"io/fs"
"log"
"net"
"net/http"
"os"
"path/filepath"
"strings"
@ -248,31 +246,20 @@ func startHTTP() {
utils.CreateDefaultFolder(bd)
// Sous-FS pointé sur "web"
sub, err := fs.Sub(webFS, "web")
if err != nil {
log.Fatalf("[HTTP] fs.Sub: %v", err)
}
// /static -> ressources front
app.StaticFS("/static", http.FS(sub))
// "/" -> index.html embarqué
app.GET("/", func(c *gin.Context) {
c.FileFromFS("index.html", http.FS(sub))
})
// Fallback SPA pour toutes les routes non-API
app.Static("/static", "./web")
app.GET("/", func(c *gin.Context) { c.File("./web/index.html") })
app.NoRoute(func(c *gin.Context) {
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
c.JSON(404, gin.H{"error": "Not found"})
return
}
c.FileFromFS("index.html", http.FS(sub))
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
c.JSON(404, gin.H{"error":"Not found"}); return
}
c.File("./web/index.html")
})
log.Println("[HTTP] Serveur Gin sur http://0.0.0.0:8080")
_ = app.Run(":8080")
}
log.Println("[HTTP] Serveur Gin sur http://0.0.0.0:8080")
_ = app.Run(":8080")
}
func main() {