diff --git a/server/ctrl/static.go b/server/ctrl/static.go index 2673811d..ec17acf1 100644 --- a/server/ctrl/static.go +++ b/server/ctrl/static.go @@ -5,6 +5,7 @@ import ( "fmt" . "github.com/mickael-kerjean/filestash/server/common" "io" + "io/fs" "net/http" URL "net/url" "os" @@ -15,6 +16,7 @@ import ( ) var ( + WWWDir fs.FS //go:embed static/www WWWEmbed embed.FS @@ -22,6 +24,10 @@ var ( HtmlPage404 []byte ) +func init() { + WWWDir = os.DirFS(GetAbsolutePath("../")) +} + func StaticHandler(_path string) func(*App, http.ResponseWriter, *http.Request) { return func(ctx *App, res http.ResponseWriter, req *http.Request) { var chroot string = GetAbsolutePath(_path) @@ -245,6 +251,9 @@ func ServeFile(res http.ResponseWriter, req *http.Request, filePath string) { } curPath := filePath + cfg.FileExt file, err := WWWEmbed.Open("static/www" + curPath) + if os.Getenv("NODE_ENV") != "" { + file, err = WWWDir.Open("server/ctrl/static/www" + curPath) + } if err != nil { continue }