This commit is contained in:
cangui 2025-08-18 19:37:38 +02:00
parent 468e0bd888
commit 388c07dba3
2 changed files with 36 additions and 24 deletions

View File

@ -18,9 +18,8 @@ services:
- SHELFY_DATA_DIR=/app/data # si ton code lit cette var (cf. patch précédent) - SHELFY_DATA_DIR=/app/data # si ton code lit cette var (cf. patch précédent)
volumes: volumes:
- shelfy_upload:/app/upload - shelfy_upload:/app/upload
- shelfy_data:/app/data # <-- volume pour SQLite - shelfy_data:/app/data
- shelfy_logs:/var/log/shelfy - shelfy_logs:/var/log/shelfy # <--- MONTE TON FRONT (lecture seule)
- ./web:/app/web:ro # <--- MONTE TON FRONT (lecture seule)
# <-- logs lus par Fail2ban # <-- logs lus par Fail2ban
labels: labels:
- traefik.http.routers.shelfy.middlewares=webdav-allow-methods@docker - traefik.http.routers.shelfy.middlewares=webdav-allow-methods@docker

25
main.go
View File

@ -8,11 +8,14 @@ import (
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/x509" "crypto/x509"
"embed"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io" "io"
"io/fs"
"log" "log"
"net" "net"
"net/http"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -232,6 +235,10 @@ func startSFTPServer(base string) {
// ---------- HTTP (Gin) ---------- // ---------- HTTP (Gin) ----------
//go:embed web/* web/**/*
// toutes les ressources front embarquées
var webFS embed.FS
func startHTTP() { func startHTTP() {
bd := db.InitDB() bd := db.InitDB()
app := gin.Default() app := gin.Default()
@ -240,21 +247,27 @@ func startHTTP() {
routes.AddRoutes(api, bd) routes.AddRoutes(api, bd)
utils.CreateDefaultFolder(bd) utils.CreateDefaultFolder(bd)
// Sert tes fichiers statiques sous /static // Sous-FS pointé sur "web"
app.Static("/static", "./web") sub, err := fs.Sub(webFS, "web")
if err != nil {
log.Fatalf("[HTTP] fs.Sub: %v", err)
}
// Sert l'index sur "/" explicitement // /static -> ressources front
app.StaticFS("/static", http.FS(sub))
// "/" -> index.html embarqué
app.GET("/", func(c *gin.Context) { app.GET("/", func(c *gin.Context) {
c.File("./web/index.html") c.FileFromFS("index.html", http.FS(sub))
}) })
// Fallback SPA : toute route non-API renvoie index.html // 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.File("./web/index.html") c.FileFromFS("index.html", http.FS(sub))
}) })
log.Println("[HTTP] Serveur Gin sur http://0.0.0.0:8080") log.Println("[HTTP] Serveur Gin sur http://0.0.0.0:8080")