all repos — website @ 3674f74cbf1e3289303487e086adfff8f1f15cfa

My website

fix redirection to wrong hostname

Alan Pearce
commit

3674f74cbf1e3289303487e086adfff8f1f15cfa

parent

3510170ca4fdc60a212dd7519596f9f7dd502998

1 file changed, 10 insertions(+), 11 deletions(-)

changed files
M internal/server/server.gointernal/server/server.go
@@ -27,12 +27,11 @@ serverHeader = fmt.Sprintf("website (%s)", ShortSHA)
) 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 @@ if runtimeConfig.InDevServer {
applyDevModeOverrides(config) } + listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, runtimeConfig.Port) + env := "development" if runtimeConfig.Production { env = "production"
@@ -85,21 +86,19 @@ mux, err := website.NewMux(config, runtimeConfig.Root)
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) }) top.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) }) - - listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, runtimeConfig.Port) return &Server{ &http.Server{