about summary refs log tree commit diff stats
path: root/internal/server/server.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-24 23:35:02 +0200
committerAlan Pearce2024-05-24 23:35:02 +0200
commite19e9de02f4e0bf5b266f467fc67a0eebc6d3f62 (patch)
treefe93fff2d77d13baa203a01b56a1d9c0c861f756 /internal/server/server.go
parent3674f74cbf1e3289303487e086adfff8f1f15cfa (diff)
downloadwebsite-e19e9de02f4e0bf5b266f467fc67a0eebc6d3f62.tar.lz
website-e19e9de02f4e0bf5b266f467fc67a0eebc6d3f62.tar.zst
website-e19e9de02f4e0bf5b266f467fc67a0eebc6d3f62.zip
enable overriding base URL
Diffstat (limited to 'internal/server/server.go')
-rw-r--r--internal/server/server.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/internal/server/server.go b/internal/server/server.go
index 11747ea..b35b6dd 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -5,6 +5,7 @@ import (
 	"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 @@ func New(runtimeConfig *Config) (*Server, error) {
 	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,