all repos — homestead @ d92a374fa1a0709d9e1cdca1d3fe7d3078d69bbb

Code for my website

fix redirection to wrong hostname

Alan Pearce
commit

d92a374fa1a0709d9e1cdca1d3fe7d3078d69bbb

parent

d2d5e331300a1c8bd785b8bcd0d43bd4ebe8fb9a

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

jump to
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{