Merge pull request #597 from sosedoff/dev-assets-mode

Enable dev assets mode with PGWEB_ASSETS_DEVMODE env var
This commit is contained in:
Dan Sosedoff 2022-12-03 20:47:54 -06:00 committed by GitHub
commit 97497b12f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -63,7 +63,7 @@ func GetHome(prefix string) http.Handler {
if prefix != "" { if prefix != "" {
prefix = "/" + prefix prefix = "/" + prefix
} }
return http.StripPrefix(prefix, http.FileServer(http.FS(static.Static))) return http.StripPrefix(prefix, static.GetHandler())
} }
func GetAssets(prefix string) http.Handler { func GetAssets(prefix string) http.Handler {
@ -72,7 +72,7 @@ func GetAssets(prefix string) http.Handler {
} else { } else {
prefix = "/static/" prefix = "/static/"
} }
return http.StripPrefix(prefix, http.FileServer(http.FS(static.Static))) return http.StripPrefix(prefix, static.GetHandler())
} }
// GetSessions renders the number of active sessions // GetSessions renders the number of active sessions

View File

@ -1,7 +1,22 @@
package static package static
import "embed" import (
"embed"
"net/http"
"os"
)
//go:embed img/* js/* css/* fonts/* //go:embed img/* js/* css/* fonts/*
//go:embed index.html //go:embed index.html
var Static embed.FS var assets embed.FS
func GetFilesystem() http.FileSystem {
if os.Getenv("PGWEB_ASSETS_DEVMODE") == "1" {
return http.Dir("./static")
}
return http.FS(assets)
}
func GetHandler() http.Handler {
return http.FileServer(GetFilesystem())
}