diff --git a/cmd/web/main.go b/cmd/web/main.go index b15619b..26ff243 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -40,6 +40,7 @@ type applicationConfig struct { localAuthEnabled bool oauth applicationOauthConfig rootUrl string + environment string } type application struct { @@ -158,7 +159,15 @@ func setupConfig(addr string) (applicationConfig, error) { oauth2Provider = os.Getenv("OAUTH2_PROVIDER") clientID = os.Getenv("OAUTH2_CLIENT_ID") clientSecret = os.Getenv("OAUTH2_CLIENT_SECRET") + environment = os.Getenv("ENVIRONMENT") ) + + if environment != "" { + c.environment = environment + } else { + c.environment = "DEV" + } + if rootUrl != "" { c.rootUrl = rootUrl } else { @@ -214,6 +223,7 @@ func setupConfig(addr string) (applicationConfig, error) { } c.oauth = o + return c, nil } diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 89884d5..c168a11 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -9,7 +9,12 @@ import ( func (app *application) routes() http.Handler { 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)