up
This commit is contained in:
parent
468e0bd888
commit
388c07dba3
@ -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
|
||||||
|
|||||||
55
main.go
55
main.go
@ -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,33 +235,43 @@ 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()
|
||||||
|
|
||||||
api := app.Group("/api/v1")
|
api := app.Group("/api/v1")
|
||||||
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.GET("/", func(c *gin.Context) {
|
app.StaticFS("/static", http.FS(sub))
|
||||||
c.File("./web/index.html")
|
|
||||||
})
|
|
||||||
|
|
||||||
// Fallback SPA : toute route non-API renvoie index.html
|
// "/" -> index.html embarqué
|
||||||
app.NoRoute(func(c *gin.Context) {
|
app.GET("/", func(c *gin.Context) {
|
||||||
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
|
c.FileFromFS("index.html", http.FS(sub))
|
||||||
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")
|
// Fallback SPA pour toutes les routes non-API
|
||||||
_ = app.Run(":8080")
|
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))
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Println("[HTTP] Serveur Gin sur http://0.0.0.0:8080")
|
||||||
|
_ = app.Run(":8080")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user