*: don't use go embed to make using custom files easier

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-01 20:35:28 +01:00
parent 31d597005f
commit f2023a7af2
4 changed files with 6 additions and 34 deletions

View File

@ -10,7 +10,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"goauthentik.io/internal/outpost/proxyv2/metrics" "goauthentik.io/internal/outpost/proxyv2/metrics"
"goauthentik.io/internal/utils/web" "goauthentik.io/internal/utils/web"
staticWeb "goauthentik.io/web"
) )
func (ps *ProxyServer) HandlePing(rw http.ResponseWriter, r *http.Request) { func (ps *ProxyServer) HandlePing(rw http.ResponseWriter, r *http.Request) {
@ -29,7 +28,7 @@ func (ps *ProxyServer) HandlePing(rw http.ResponseWriter, r *http.Request) {
} }
func (ps *ProxyServer) HandleStatic(rw http.ResponseWriter, r *http.Request) { func (ps *ProxyServer) HandleStatic(rw http.ResponseWriter, r *http.Request) {
staticFs := http.FileServer(http.FS(staticWeb.StaticDist)) staticFs := http.FileServer(http.Dir("./website/static/"))
before := time.Now() before := time.Now()
web.DisableIndex(http.StripPrefix("/akprox/static", staticFs)).ServeHTTP(rw, r) web.DisableIndex(http.StripPrefix("/akprox/static", staticFs)).ServeHTTP(rw, r)
after := time.Since(before) after := time.Since(before)

View File

@ -9,7 +9,6 @@ import (
"goauthentik.io/internal/constants" "goauthentik.io/internal/constants"
"goauthentik.io/internal/utils/web" "goauthentik.io/internal/utils/web"
staticWeb "goauthentik.io/web" staticWeb "goauthentik.io/web"
staticDocs "goauthentik.io/website"
) )
func (ws *WebServer) configureStatic() { func (ws *WebServer) configureStatic() {
@ -18,24 +17,10 @@ func (ws *WebServer) configureStatic() {
indexLessRouter.Use(web.DisableIndex) indexLessRouter.Use(web.DisableIndex)
// Media files, always local // Media files, always local
fs := http.FileServer(http.Dir(config.G.Paths.Media)) fs := http.FileServer(http.Dir(config.G.Paths.Media))
var distHandler http.Handler distFs := http.FileServer(http.Dir("./web/dist"))
var distFs http.Handler distHandler := http.StripPrefix("/static/dist/", distFs)
var authentikHandler http.Handler authentikHandler := http.StripPrefix("/static/authentik/", http.FileServer(http.Dir("./web/authentik")))
var helpHandler http.Handler helpHandler := http.FileServer(http.Dir("./website/help/"))
if config.G.Debug || config.G.Web.LoadLocalFiles {
ws.log.Debug("Using local static files")
distFs = http.FileServer(http.Dir("./web/dist"))
distHandler = http.StripPrefix("/static/dist/", distFs)
authentikHandler = http.StripPrefix("/static/authentik/", http.FileServer(http.Dir("./web/authentik")))
helpHandler = http.FileServer(http.Dir("./website/help/"))
} else {
statRouter.Use(ws.staticHeaderMiddleware)
ws.log.Debug("Using packaged static files with aggressive caching")
distFs = http.FileServer(http.FS(staticWeb.StaticDist))
distHandler = http.StripPrefix("/static", distFs)
authentikHandler = http.StripPrefix("/static", http.FileServer(http.FS(staticWeb.StaticAuthentik)))
helpHandler = http.FileServer(http.FS(staticDocs.Help))
}
indexLessRouter.PathPrefix("/static/dist/").Handler(distHandler) indexLessRouter.PathPrefix("/static/dist/").Handler(distHandler)
indexLessRouter.PathPrefix("/static/authentik/").Handler(authentikHandler) indexLessRouter.PathPrefix("/static/authentik/").Handler(authentikHandler)

View File

@ -1,12 +1,6 @@
package web package web
import "embed" import _ "embed"
//go:embed dist/*
var StaticDist embed.FS
//go:embed authentik
var StaticAuthentik embed.FS
//go:embed robots.txt //go:embed robots.txt
var RobotsTxt []byte var RobotsTxt []byte

View File

@ -1,6 +0,0 @@
package web
import "embed"
//go:embed help/*
var Help embed.FS