diff options
Diffstat (limited to 'modules/setting/setting.go')
-rw-r--r-- | modules/setting/setting.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 4c2fba8048..199f27a21f 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -626,8 +626,10 @@ func NewContext() { StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/") AppSubURLDepth = strings.Count(AppSubURL, "/") // Check if Domain differs from AppURL domain than update it to AppURL's domain - // TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8 - urlHostname := strings.SplitN(appURL.Host, ":", 2)[0] + urlHostname, _, err := net.SplitHostPort(appURL.Host) + if err != nil { + log.Fatal("Invalid host in ROOT_URL '%s': %s", appURL.Host, err) + } if urlHostname != Domain && net.ParseIP(urlHostname) == nil { Domain = urlHostname } @@ -643,11 +645,10 @@ func NewContext() { default: defaultLocalURL = string(Protocol) + "://" if HTTPAddr == "0.0.0.0" { - defaultLocalURL += "localhost" + defaultLocalURL += net.JoinHostPort("localhost", HTTPPort) + "/" } else { - defaultLocalURL += HTTPAddr + defaultLocalURL += net.JoinHostPort(HTTPAddr, HTTPPort) + "/" } - defaultLocalURL += ":" + HTTPPort + "/" } LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL) RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false) |