mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-15 12:55:41 +01:00
feature (dev): server static file from fs in dev mode
This commit is contained in:
parent
7d5719445c
commit
ac7bf9f173
1 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue