Skip to content

Commit 5b74660

Browse files
authored
Skip frontend ROOT_URL check on installation page, remove unnecessary global var (#19291)
Skip `checkAppUrl` message on installation page because the ROOT_URL is not determined yet Move global var `supportedDbTypeNames` into `install.Init` as a local var
1 parent 89b9d42 commit 5b74660

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

routers/install/install.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@ const (
4242
tplPostInstall base.TplName = "post-install"
4343
)
4444

45-
var supportedDbTypeNames []map[string]string // use a slice to keep order
46-
func getDbTypeNames() []map[string]string {
47-
if supportedDbTypeNames == nil {
48-
for _, t := range setting.SupportedDatabaseTypes {
49-
supportedDbTypeNames = append(supportedDbTypeNames, map[string]string{"type": t, "name": setting.DatabaseTypeNames[t]})
50-
}
45+
// getSupportedDbTypeNames returns a slice for supported database types and names. The slice is used to keep the order
46+
func getSupportedDbTypeNames() (dbTypeNames []map[string]string) {
47+
for _, t := range setting.SupportedDatabaseTypes {
48+
dbTypeNames = append(dbTypeNames, map[string]string{"type": t, "name": setting.DatabaseTypeNames[t]})
5149
}
52-
return supportedDbTypeNames
50+
return dbTypeNames
5351
}
5452

5553
// Init prepare for rendering installation page
5654
func Init(next http.Handler) http.Handler {
5755
rnd := templates.HTMLRenderer()
58-
56+
dbTypeNames := getSupportedDbTypeNames()
5957
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
6058
if setting.InstallLock {
6159
resp.Header().Add("Refresh", "1; url="+setting.AppURL+"user/login")
@@ -74,7 +72,7 @@ func Init(next http.Handler) http.Handler {
7472
"i18n": locale,
7573
"Title": locale.Tr("install.install"),
7674
"PageIsInstall": true,
77-
"DbTypeNames": getDbTypeNames(),
75+
"DbTypeNames": dbTypeNames,
7876
"AllLangs": translation.AllLangs(),
7977
"PageStartTime": startTime,
8078

web_src/js/features/common-global.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ export function checkAppUrl() {
358358
if (curUrl.startsWith(appUrl)) {
359359
return;
360360
}
361+
if (document.querySelector('.page-content.install')) {
362+
return; // no need to show the message on the installation page
363+
}
361364
showGlobalErrorMessage(`Your ROOT_URL in app.ini is ${appUrl} but you are visiting ${curUrl}
362365
You should set ROOT_URL correctly, otherwise the web may not work correctly.`);
363366
}

0 commit comments

Comments
 (0)