enable overriding base URL
Alan Pearce alan@alanpearce.eu
Fri, 24 May 2024 23:35:02 +0200
1 files changed, 10 insertions(+), 4 deletions(-)
jump to
M internal/server/server.go → internal/server/server.go
@@ -5,6 +5,7 @@ "context" "fmt" "net" "net/http" + "net/url" "os" "slices" "time" @@ -38,9 +39,15 @@ type Server struct { *http.Server } -func applyDevModeOverrides(config *cfg.Config) { +func applyDevModeOverrides(config *cfg.Config, listenAddress string) { config.CSP.ScriptSrc = slices.Insert(config.CSP.ScriptSrc, 0, "'unsafe-inline'") config.CSP.ConnectSrc = slices.Insert(config.CSP.ConnectSrc, 0, "'self'") + config.BaseURL = cfg.URL{ + URL: &url.URL{ + Scheme: "http", + Host: listenAddress, + }, + } } func serverHeaderHandler(wrappedHandler http.Handler) http.Handler { @@ -56,15 +63,14 @@ config, err := cfg.GetConfig() if err != nil { return nil, errors.WithMessage(err, "error parsing configuration file") } - if runtimeConfig.InDevServer { - applyDevModeOverrides(config) - } listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, runtimeConfig.Port) env := "development" if runtimeConfig.Production { env = "production" + } else { + applyDevModeOverrides(config, listenAddress) } err = sentry.Init(sentry.ClientOptions{ EnableTracing: true,