up
This commit is contained in:
parent
e60adf921b
commit
88c2e12b14
23
main.go
23
main.go
@ -12,10 +12,8 @@ import (
|
|||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -248,28 +246,17 @@ func startHTTP() {
|
|||||||
utils.CreateDefaultFolder(bd)
|
utils.CreateDefaultFolder(bd)
|
||||||
|
|
||||||
// Sous-FS pointé sur "web"
|
// Sous-FS pointé sur "web"
|
||||||
sub, err := fs.Sub(webFS, "web")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("[HTTP] fs.Sub: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// /static -> ressources front
|
// /static -> ressources front
|
||||||
app.StaticFS("/static", http.FS(sub))
|
app.Static("/static", "./web")
|
||||||
|
app.GET("/", func(c *gin.Context) { c.File("./web/index.html") })
|
||||||
// "/" -> 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.NoRoute(func(c *gin.Context) {
|
app.NoRoute(func(c *gin.Context) {
|
||||||
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
|
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
|
||||||
c.JSON(404, gin.H{"error": "Not found"})
|
c.JSON(404, gin.H{"error":"Not found"}); return
|
||||||
return
|
|
||||||
}
|
}
|
||||||
c.FileFromFS("index.html", http.FS(sub))
|
c.File("./web/index.html")
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("[HTTP] Serveur Gin sur http://0.0.0.0:8080")
|
log.Println("[HTTP] Serveur Gin sur http://0.0.0.0:8080")
|
||||||
_ = app.Run(":8080")
|
_ = app.Run(":8080")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user