From 498bcf8a787e7a45369702e46abf40d2bf25f75e Mon Sep 17 00:00:00 2001 From: shirainbown Date: Thu, 18 Jun 2026 23:12:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Docker=20=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=97=B6=20r.Static=20=E4=B8=8E=20/api=20=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/server/main.go b/server/main.go index 2f2617d..aef3b7e 100644 --- a/server/main.go +++ b/server/main.go @@ -120,9 +120,23 @@ func main() { // Static files if cfg.WebStaticPath != "" { - r.Static("/", cfg.WebStaticPath) + staticFS := os.DirFS(cfg.WebStaticPath) + fileServer := http.FileServer(http.FS(staticFS)) r.NoRoute(func(c *gin.Context) { - c.File(cfg.WebStaticPath + "/index.html") + path := c.Request.URL.Path + // Handle assets at any path depth + if idx := strings.Index(path, "/assets/"); idx >= 0 { + c.Request.URL.Path = path[idx:] + fileServer.ServeHTTP(c.Writer, c.Request) + return + } + if path == "/favicon.ico" { + fileServer.ServeHTTP(c.Writer, c.Request) + return + } + // SPA fallback: all other paths serve index.html + c.Request.URL.Path = "/" + fileServer.ServeHTTP(c.Writer, c.Request) }) } else { staticFS, err := fs.Sub(webFS, "static")