fix: 修复assets文件路径错误
- 修复通配符参数filepath只包含assets/后面的部分的问题 - 正确拼接assets/前缀以查找嵌入的静态资源文件
This commit is contained in:
+2
-8
@@ -262,15 +262,9 @@ func setupEmbeddedFrontend(r *gin.Engine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.GET("/assets/*filepath", func(c *gin.Context) {
|
r.GET("/assets/*filepath", func(c *gin.Context) {
|
||||||
filepath := strings.TrimPrefix(c.Request.URL.Path, "/assets/")
|
filepath := c.Param("filepath")
|
||||||
file, err := distFS.Open(filepath)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(404, gin.H{"error": "asset not found"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
file.Close()
|
|
||||||
c.Header("Cache-Control", "public, max-age=31536000, immutable")
|
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) {
|
r.NoRoute(func(c *gin.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user