diff options
author | Mike Fellows <Mike.Fellows@shaw.ca> | 2017-06-22 00:35:14 -0700 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-22 15:35:14 +0800 |
commit | 32f1c41f288a654fc8e5642a6681bf492710da3e (patch) | |
tree | 393f70a01022a532c5bcd462e1b260ce33f74909 /modules/setting | |
parent | 2852cca99ea1844132927390db8ce08903997e21 (diff) | |
download | gitea-32f1c41f288a654fc8e5642a6681bf492710da3e.tar.gz gitea-32f1c41f288a654fc8e5642a6681bf492710da3e.zip |
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 <mike.fellows@shaw.ca>
Diffstat (limited to 'modules/setting')
-rw-r--r-- | modules/setting/setting.go | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 63635636b2..6307cc87d6 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() |