g: fix static and media caching not working properly
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
3e5dfcbd0f
commit
30033d1f90
|
@ -10,15 +10,19 @@ import (
|
||||||
|
|
||||||
func (ws *WebServer) configureStatic() {
|
func (ws *WebServer) configureStatic() {
|
||||||
statRouter := ws.lh.NewRoute().Subrouter()
|
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 {
|
if config.G.Debug || config.G.Web.LoadLocalFiles {
|
||||||
ws.log.Debug("Using local static files")
|
ws.log.Debug("Using local static files")
|
||||||
ws.lh.PathPrefix("/static/dist").Handler(http.StripPrefix("/static/dist", http.FileServer(http.Dir("./web/dist"))))
|
statRouter.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/authentik").Handler(http.StripPrefix("/static/authentik", http.FileServer(http.Dir("./web/authentik"))))
|
||||||
|
statRouter.PathPrefix("/media").Handler(http.StripPrefix("/media", fs))
|
||||||
} else {
|
} else {
|
||||||
statRouter.Use(ws.staticHeaderMiddleware)
|
statRouter.Use(ws.staticHeaderMiddleware)
|
||||||
ws.log.Debug("Using packaged static files with aggressive caching")
|
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))))
|
statRouter.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/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) {
|
ws.lh.Path("/robots.txt").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
rw.Header()["Content-Type"] = []string{"text/plain"}
|
rw.Header()["Content-Type"] = []string{"text/plain"}
|
||||||
|
@ -30,8 +34,6 @@ func (ws *WebServer) configureStatic() {
|
||||||
rw.WriteHeader(200)
|
rw.WriteHeader(200)
|
||||||
rw.Write(staticWeb.SecurityTxt)
|
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 {
|
func (ws *WebServer) staticHeaderMiddleware(h http.Handler) http.Handler {
|
||||||
|
|
Reference in New Issue