debug: 添加嵌入文件系统调试日志
- 启动时列出所有嵌入的assets文件 - 请求assets文件时添加文件查找日志
This commit is contained in:
+23
-1
@@ -256,6 +256,17 @@ func setupEmbeddedFrontend(r *gin.Engine) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[Embed] Listing embedded files in assets/:")
|
||||
fs.WalkDir(distFS, "assets", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !d.IsDir() {
|
||||
log.Printf("[Embed] %s", path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
indexHTML, err := fs.ReadFile(distFS, "index.html")
|
||||
if err != nil {
|
||||
log.Printf("Warning: index.html not found in embedded dist")
|
||||
@@ -269,8 +280,19 @@ func setupEmbeddedFrontend(r *gin.Engine) {
|
||||
if err != nil {
|
||||
decodedPath = filepath
|
||||
}
|
||||
|
||||
fullPath := "assets/" + decodedPath
|
||||
|
||||
f, err := distFS.Open(fullPath)
|
||||
if err != nil {
|
||||
log.Printf("[Assets] File not found in embedded FS: %s, error: %v", fullPath, err)
|
||||
c.Status(404)
|
||||
return
|
||||
}
|
||||
f.Close()
|
||||
|
||||
c.Header("Cache-Control", "public, max-age=31536000, immutable")
|
||||
c.FileFromFS("assets/"+decodedPath, http.FS(distFS))
|
||||
c.FileFromFS(fullPath, http.FS(distFS))
|
||||
})
|
||||
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user