修复 debug 模式下静态文件路径问题

This commit is contained in:
2026-04-22 20:49:10 +08:00
parent 2f0adb12ba
commit 9fe251922e
+11 -1
View File
@@ -4,6 +4,8 @@ import (
"io/fs"
"net/http"
"os"
"path/filepath"
"runtime"
"next-terminal/server/api"
"next-terminal/server/api/worker"
@@ -19,7 +21,15 @@ import (
func getFS(useOS bool) fs.FS {
if useOS {
log.Debug("using live mode")
return os.DirFS("web/build")
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("failed to get caller info")
}
appDir := filepath.Dir(filename)
baseDir := filepath.Dir(filepath.Dir(appDir))
webBuildPath := filepath.Join(baseDir, "web", "build")
log.Debug("web build path: " + webBuildPath)
return os.DirFS(webBuildPath)
}
log.Debug("using embed mode")