From 44d65f1fbc2b4b8c4a5cc5a44fd14034b6f7735c Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 May 2026 14:38:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dassets=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复通配符参数filepath只包含assets/后面的部分的问题 - 正确拼接assets/前缀以查找嵌入的静态资源文件 --- backend/cmd/main.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index ba53593..be759b1 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -262,15 +262,9 @@ func setupEmbeddedFrontend(r *gin.Engine) { } r.GET("/assets/*filepath", func(c *gin.Context) { - filepath := strings.TrimPrefix(c.Request.URL.Path, "/assets/") - file, err := distFS.Open(filepath) - if err != nil { - c.JSON(404, gin.H{"error": "asset not found"}) - return - } - file.Close() + filepath := c.Param("filepath") c.Header("Cache-Control", "public, max-age=31536000, immutable") - c.FileFromFS(c.Request.URL.Path, http.FS(distFS)) + c.FileFromFS("assets/"+filepath, http.FS(distFS)) }) r.NoRoute(func(c *gin.Context) {