diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/server/server.go | 21 |
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, |