up
This commit is contained in:
parent
e60adf921b
commit
88c2e12b14
33
main.go
33
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() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user