use static filesystem for dev environment

This commit is contained in:
yequari 2025-07-24 21:45:58 -07:00
parent bcbba7e872
commit 65801464f1
2 changed files with 16 additions and 1 deletions

View File

@ -40,6 +40,7 @@ type applicationConfig struct {
localAuthEnabled bool localAuthEnabled bool
oauth applicationOauthConfig oauth applicationOauthConfig
rootUrl string rootUrl string
environment string
} }
type application struct { type application struct {
@ -158,7 +159,15 @@ func setupConfig(addr string) (applicationConfig, error) {
oauth2Provider = os.Getenv("OAUTH2_PROVIDER") oauth2Provider = os.Getenv("OAUTH2_PROVIDER")
clientID = os.Getenv("OAUTH2_CLIENT_ID") clientID = os.Getenv("OAUTH2_CLIENT_ID")
clientSecret = os.Getenv("OAUTH2_CLIENT_SECRET") clientSecret = os.Getenv("OAUTH2_CLIENT_SECRET")
environment = os.Getenv("ENVIRONMENT")
) )
if environment != "" {
c.environment = environment
} else {
c.environment = "DEV"
}
if rootUrl != "" { if rootUrl != "" {
c.rootUrl = rootUrl c.rootUrl = rootUrl
} else { } else {
@ -214,6 +223,7 @@ func setupConfig(addr string) (applicationConfig, error) {
} }
c.oauth = o c.oauth = o
return c, nil return c, nil
} }

View File

@ -9,7 +9,12 @@ import (
func (app *application) routes() http.Handler { func (app *application) routes() http.Handler {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("GET /static/", http.FileServerFS(ui.Files)) if app.config.environment == "PROD" {
mux.Handle("GET /static/", http.FileServerFS(ui.Files))
} else {
fileServer := http.FileServer(http.Dir("./ui/static/"))
mux.Handle("GET /static/", http.StripPrefix("/static", fileServer))
}
mux.HandleFunc("GET /ping", ping) mux.HandleFunc("GET /ping", ping)