diff --git a/internal/web/web_static.go b/internal/web/web_static.go index 06d30eddd..ccee1c98d 100644 --- a/internal/web/web_static.go +++ b/internal/web/web_static.go @@ -10,15 +10,19 @@ import ( func (ws *WebServer) configureStatic() { statRouter := ws.lh.NewRoute().Subrouter() + // Media files, always local + fs := http.FileServer(http.Dir(config.G.Paths.Media)) if config.G.Debug || config.G.Web.LoadLocalFiles { ws.log.Debug("Using local static files") - ws.lh.PathPrefix("/static/dist").Handler(http.StripPrefix("/static/dist", http.FileServer(http.Dir("./web/dist")))) - ws.lh.PathPrefix("/static/authentik").Handler(http.StripPrefix("/static/authentik", http.FileServer(http.Dir("./web/authentik")))) + statRouter.PathPrefix("/static/dist").Handler(http.StripPrefix("/static/dist", http.FileServer(http.Dir("./web/dist")))) + statRouter.PathPrefix("/static/authentik").Handler(http.StripPrefix("/static/authentik", http.FileServer(http.Dir("./web/authentik")))) + statRouter.PathPrefix("/media").Handler(http.StripPrefix("/media", fs)) } else { statRouter.Use(ws.staticHeaderMiddleware) ws.log.Debug("Using packaged static files with aggressive caching") - ws.lh.PathPrefix("/static/dist").Handler(http.StripPrefix("/static", http.FileServer(http.FS(staticWeb.StaticDist)))) - ws.lh.PathPrefix("/static/authentik").Handler(http.StripPrefix("/static", http.FileServer(http.FS(staticWeb.StaticAuthentik)))) + statRouter.PathPrefix("/static/dist").Handler(http.StripPrefix("/static", http.FileServer(http.FS(staticWeb.StaticDist)))) + statRouter.PathPrefix("/static/authentik").Handler(http.StripPrefix("/static", http.FileServer(http.FS(staticWeb.StaticAuthentik)))) + statRouter.PathPrefix("/media").Handler(http.StripPrefix("/media", fs)) } ws.lh.Path("/robots.txt").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { rw.Header()["Content-Type"] = []string{"text/plain"} @@ -30,8 +34,6 @@ func (ws *WebServer) configureStatic() { rw.WriteHeader(200) rw.Write(staticWeb.SecurityTxt) }) - // Media files, always local - ws.lh.PathPrefix("/media").Handler(http.StripPrefix("/media", http.FileServer(http.Dir(config.G.Paths.Media)))) } func (ws *WebServer) staticHeaderMiddleware(h http.Handler) http.Handler {