fix: 修复assets文件路径错误

- 修复通配符参数filepath只包含assets/后面的部分的问题
- 正确拼接assets/前缀以查找嵌入的静态资源文件
This commit is contained in:
2026-05-04 14:38:46 +08:00
parent 16af684a32
commit 44d65f1fbc
+2 -8
View File
@@ -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) {