Skip to content

Commit

Permalink
ROOT_URL setting use the default as shown in conf/app.ini
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
MCF committed Jun 22, 2017
1 parent 97f7f88 commit 1513730
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,18 +611,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" {
Expand All @@ -643,6 +631,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()
Expand Down

0 comments on commit 1513730

Please sign in to comment.