all repos — homestead @ 9a7334b3ec61fac7d5ec1daad94dcb8b9e9143ea

Code for my website

make hostname-based redirection configurable

Alan Pearce
commit

9a7334b3ec61fac7d5ec1daad94dcb8b9e9143ea

parent

ee5162916eb735ee70f0bae40db0054197a4451b

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

jump to
M internal/server/server.gointernal/server/server.go
@@ -29,6 +29,7 @@
type Config struct { Development bool `conf:"default:false,flag:dev"` Root string `conf:"default:website"` + Redirect bool `conf:"default:false"` ListenAddress string `conf:"default:localhost"` Port string `conf:"default:3000,short:p"` TLS bool `conf:"default:false"`
@@ -132,14 +133,16 @@ if err != nil {
return nil, errors.Wrap(err, "could not create website mux") } log.Debug("binding main handler to", "host", listenAddress) - hostname := config.BaseURL.Hostname() - loggingMux.Handle(hostname+"/", mux) - - loggingMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - newURL := config.BaseURL.JoinPath(r.URL.String()) - http.Redirect(w, r, newURL.String(), 301) - }) + if runtimeConfig.Development || runtimeConfig.Redirect { + loggingMux.Handle(config.BaseURL.Hostname()+"/", mux) + loggingMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + newURL := config.BaseURL.JoinPath(r.URL.String()) + http.Redirect(w, r, newURL.String(), 301) + }) + } else { + loggingMux.Handle("/", mux) + } top.Handle("/", serverHeaderHandler(