diff options
Diffstat (limited to 'internal/server/server.go')
-rw-r--r-- | internal/server/server.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index ba825aa..21c7743 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -190,15 +190,20 @@ func New(runtimeConfig *Config, log *log.Logger) (*Server, error) { replace := "${1}." + config.Domains[0] loggingMux.Handle(config.BaseURL.Hostname()+"/", mux) loggingMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if slices.Contains(config.Domains, r.Host) { + switch true { + case slices.Contains(config.Domains, r.Host): path, _ := website.CanonicalisePath(r.URL.Path) - newURL := config.BaseURL.JoinPath(path) - http.Redirect(w, r, newURL.String(), http.StatusMovedPermanently) - } else if re.MatchString(r.Host) { + http.Redirect( + w, + r, + config.BaseURL.JoinPath(path).String(), + http.StatusMovedPermanently, + ) + case re.MatchString(r.Host): url := config.BaseURL url.Host = re.ReplaceAllString(r.Host, replace) http.Redirect(w, r, url.String(), http.StatusTemporaryRedirect) - } else { + case true: http.NotFound(w, r) } }) |