mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 02:09:28 +08:00
add CSP env var to set a custom Content-Security-Policy header value
This commit is contained in:
@@ -90,7 +90,7 @@ func (h *Hub) Run() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// serve site
|
// serve web ui
|
||||||
h.app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
h.app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||||
switch isGoRun {
|
switch isGoRun {
|
||||||
case true:
|
case true:
|
||||||
@@ -98,12 +98,17 @@ func (h *Hub) Run() {
|
|||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: "localhost:5173",
|
Host: "localhost:5173",
|
||||||
})
|
})
|
||||||
e.Router.GET("/static/*", apis.StaticDirectoryHandler(os.DirFS("../../site/public/static"), false))
|
|
||||||
e.Router.Any("/*", echo.WrapHandler(proxy))
|
e.Router.Any("/*", echo.WrapHandler(proxy))
|
||||||
// e.Router.Any("/", echo.WrapHandler(proxy))
|
|
||||||
default:
|
default:
|
||||||
e.Router.GET("/static/*", apis.StaticDirectoryHandler(site.Static, false))
|
csp, cspExists := os.LookupEnv("CSP")
|
||||||
e.Router.Any("/*", apis.StaticDirectoryHandler(site.Dist, true))
|
e.Router.Any("/*", func(c echo.Context) error {
|
||||||
|
if cspExists {
|
||||||
|
c.Response().Header().Del("X-Frame-Options")
|
||||||
|
c.Response().Header().Set("Content-Security-Policy", csp)
|
||||||
|
}
|
||||||
|
indexFallback := !strings.HasPrefix(c.Request().URL.Path, "/static/")
|
||||||
|
return apis.StaticDirectoryHandler(site.Dist, indexFallback)(c)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@@ -11,5 +11,3 @@ import (
|
|||||||
var assets embed.FS
|
var assets embed.FS
|
||||||
|
|
||||||
var Dist = echo.MustSubFS(assets, "dist")
|
var Dist = echo.MustSubFS(assets, "dist")
|
||||||
|
|
||||||
var Static = echo.MustSubFS(assets, "dist/static")
|
|
||||||
|
Reference in New Issue
Block a user