about summary refs log tree commit diff stats
path: root/internal/server/server.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-24 23:34:36 +0200
committerAlan Pearce2024-05-24 23:34:36 +0200
commit3674f74cbf1e3289303487e086adfff8f1f15cfa (patch)
treecd275628c60409b045bc11755b042daa40947622 /internal/server/server.go
parent3510170ca4fdc60a212dd7519596f9f7dd502998 (diff)
downloadwebsite-3674f74cbf1e3289303487e086adfff8f1f15cfa.tar.lz
website-3674f74cbf1e3289303487e086adfff8f1f15cfa.tar.zst
website-3674f74cbf1e3289303487e086adfff8f1f15cfa.zip
fix redirection to wrong hostname
Diffstat (limited to 'internal/server/server.go')
-rw-r--r--internal/server/server.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/internal/server/server.go b/internal/server/server.go
index c72368c..11747ea 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -27,12 +27,11 @@ var (
 )
 
 type Config struct {
-	Production    bool    `conf:"default:false"`
-	InDevServer   bool    `conf:"default:false"`
-	Root          string  `conf:"default:website"`
-	ListenAddress string  `conf:"default:localhost"`
-	Port          string  `conf:"default:3000,short:p"`
-	BaseURL       cfg.URL `conf:"default:http://localhost:3000,short:b"`
+	Production    bool   `conf:"default:false"`
+	InDevServer   bool   `conf:"default:false"`
+	Root          string `conf:"default:website"`
+	ListenAddress string `conf:"default:localhost"`
+	Port          string `conf:"default:3000,short:p"`
 }
 
 type Server struct {
@@ -61,6 +60,8 @@ func New(runtimeConfig *Config) (*Server, error) {
 		applyDevModeOverrides(config)
 	}
 
+	listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, runtimeConfig.Port)
+
 	env := "development"
 	if runtimeConfig.Production {
 		env = "production"
@@ -85,13 +86,13 @@ func New(runtimeConfig *Config) (*Server, error) {
 	if err != nil {
 		return nil, errors.Wrap(err, "could not create website mux")
 	}
-	log.Debug("binding main handler to", "host", runtimeConfig.BaseURL.Hostname()+"/")
-	hostname := runtimeConfig.BaseURL.Hostname()
+	log.Debug("binding main handler to", "host", listenAddress)
+	hostname := config.BaseURL.Hostname()
 
 	top.Handle(hostname+"/", mux)
 
 	top.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
-		newURL := runtimeConfig.BaseURL.JoinPath(r.URL.String())
+		newURL := config.BaseURL.JoinPath(r.URL.String())
 		http.Redirect(w, r, newURL.String(), 301)
 	})
 
@@ -99,8 +100,6 @@ func New(runtimeConfig *Config) (*Server, error) {
 		w.WriteHeader(http.StatusNoContent)
 	})
 
-	listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, runtimeConfig.Port)
-
 	return &Server{
 		&http.Server{
 			Addr:              listenAddress,