Skip to content

Commit 32f1c41

Browse files
MCFlunny
authored andcommitted
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 <[email protected]>
1 parent 2852cca commit 32f1c41

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

modules/setting/setting.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,18 +624,6 @@ please consider changing to GITEA_CUSTOM`)
624624

625625
sec := Cfg.Section("server")
626626
AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")
627-
AppURL = sec.Key("ROOT_URL").MustString("http://localhost:3000/")
628-
AppURL = strings.TrimRight(AppURL, "/") + "/"
629-
630-
// Check if has app suburl.
631-
url, err := url.Parse(AppURL)
632-
if err != nil {
633-
log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppURL, err)
634-
}
635-
// Suburl should start with '/' and end without '/', such as '/{subpath}'.
636-
// This value is empty if site does not have sub-url.
637-
AppSubURL = strings.TrimSuffix(url.Path, "/")
638-
AppSubURLDepth = strings.Count(AppSubURL, "/")
639627

640628
Protocol = HTTP
641629
if sec.Key("PROTOCOL").String() == "https" {
@@ -656,6 +644,24 @@ please consider changing to GITEA_CUSTOM`)
656644
Domain = sec.Key("DOMAIN").MustString("localhost")
657645
HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
658646
HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
647+
648+
defaultAppURL := string(Protocol) + "://" + Domain
649+
if (Protocol == HTTP && HTTPPort != "80") || (Protocol == HTTPS && HTTPPort != "443") {
650+
defaultAppURL += ":" + HTTPPort
651+
}
652+
AppURL = sec.Key("ROOT_URL").MustString(defaultAppURL)
653+
AppURL = strings.TrimRight(AppURL, "/") + "/"
654+
655+
// Check if has app suburl.
656+
url, err := url.Parse(AppURL)
657+
if err != nil {
658+
log.Fatal(4, "Invalid ROOT_URL '%s': %s", AppURL, err)
659+
}
660+
// Suburl should start with '/' and end without '/', such as '/{subpath}'.
661+
// This value is empty if site does not have sub-url.
662+
AppSubURL = strings.TrimSuffix(url.Path, "/")
663+
AppSubURLDepth = strings.Count(AppSubURL, "/")
664+
659665
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(string(Protocol) + "://localhost:" + HTTPPort + "/")
660666
OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
661667
DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()

0 commit comments

Comments
 (0)