added staging banner

This commit is contained in:
2026-03-07 13:24:36 +11:00
parent a1ee591e6f
commit eaaa62de43
5 changed files with 26 additions and 14 deletions

View File

@@ -44,17 +44,21 @@ func addMiddleware(
func devMode(cfg *config.Config) hws.Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if cfg.Flags.DevMode {
devInfo := contexts.DevInfo{
WebsocketBase: "ws://" + cfg.HWS.Host + ":" + strconv.FormatUint(cfg.HWS.Port, 10),
HTMXLog: true,
}
ctx := context.WithValue(r.Context(), contexts.DevModeKey, devInfo)
req := r.WithContext(ctx)
next.ServeHTTP(w, req)
if !cfg.Flags.DevMode && !cfg.Flags.Staging {
next.ServeHTTP(w, r)
return
}
next.ServeHTTP(w, r)
devInfo := contexts.DevInfo{}
if cfg.Flags.DevMode {
devInfo.WebsocketBase = "ws://" + cfg.HWS.Host + ":" + strconv.FormatUint(cfg.HWS.Port, 10)
devInfo.HTMXLog = true
}
if cfg.Flags.Staging {
devInfo.StagingBanner = true
}
ctx := context.WithValue(r.Context(), contexts.DevModeKey, devInfo)
req := r.WithContext(ctx)
next.ServeHTTP(w, req)
},
)
}