diff --git a/main.go b/main.go index 601f149..28eb27b 100644 --- a/main.go +++ b/main.go @@ -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() {