From 32f1c41f288a654fc8e5642a6681bf492710da3e Mon Sep 17 00:00:00 2001 From: Mike Fellows Date: Thu, 22 Jun 2017 00:35:14 -0700 Subject: [PATCH] ROOT_URL setting use the default as shown in conf/app.ini (#1823) The well commented conf/app.ini file that comes with the code shows the ROOT_URL (i.e. setting.AppURL) as: ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/ However the installed custom/conf/app.ini file does not include this setting as shown, and the default in the setting module was hard coded to http://localhost:3000/ instead of what is shown above. With this change the ROOT_URL will default to what is shown above if it is not set in the custom/conf/app.ini. Of course it is still possible to override the default by adding the ROOT_URL setting to your custom/conf/app.ini file as usual. Signed-off-by: Mike Fellows --- modules/setting/setting.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 63635636b..6307cc87d 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -624,18 +624,6 @@ please consider changing to GITEA_CUSTOM`) sec := Cfg.Section("server") AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea") - AppURL = sec.Key("ROOT_URL").MustString("http://localhost:3000/") - AppURL = strings.TrimRight(AppURL, "/") + "/" - - // Check if has app suburl. - url, err := url.Parse(AppURL) - if err != nil { - log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppURL, err) - } - // Suburl should start with '/' and end without '/', such as '/{subpath}'. - // This value is empty if site does not have sub-url. - AppSubURL = strings.TrimSuffix(url.Path, "/") - AppSubURLDepth = strings.Count(AppSubURL, "/") Protocol = HTTP if sec.Key("PROTOCOL").String() == "https" { @@ -656,6 +644,24 @@ please consider changing to GITEA_CUSTOM`) Domain = sec.Key("DOMAIN").MustString("localhost") HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0") HTTPPort = sec.Key("HTTP_PORT").MustString("3000") + + defaultAppURL := string(Protocol) + "://" + Domain + if (Protocol == HTTP && HTTPPort != "80") || (Protocol == HTTPS && HTTPPort != "443") { + defaultAppURL += ":" + HTTPPort + } + AppURL = sec.Key("ROOT_URL").MustString(defaultAppURL) + AppURL = strings.TrimRight(AppURL, "/") + "/" + + // Check if has app suburl. + url, err := url.Parse(AppURL) + if err != nil { + log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppURL, err) + } + // Suburl should start with '/' and end without '/', such as '/{subpath}'. + // This value is empty if site does not have sub-url. + AppSubURL = strings.TrimSuffix(url.Path, "/") + AppSubURLDepth = strings.Count(AppSubURL, "/") + LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(string(Protocol) + "://localhost:" + HTTPPort + "/") OfflineMode = sec.Key("OFFLINE_MODE").MustBool() DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()