Skip to content

Commit

Permalink
Skip frontend ROOT_URL check on installation page, remove unnecessary…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
wxiaoguang committed Apr 1, 2022
1 parent 89b9d42 commit 5b74660
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 7 additions & 9 deletions routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,18 @@ const (
tplPostInstall base.TplName = "post-install"
)

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

// Init prepare for rendering installation page
func Init(next http.Handler) http.Handler {
rnd := templates.HTMLRenderer()

dbTypeNames := getSupportedDbTypeNames()
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if setting.InstallLock {
resp.Header().Add("Refresh", "1; url="+setting.AppURL+"user/login")
Expand All @@ -74,7 +72,7 @@ func Init(next http.Handler) http.Handler {
"i18n": locale,
"Title": locale.Tr("install.install"),
"PageIsInstall": true,
"DbTypeNames": getDbTypeNames(),
"DbTypeNames": dbTypeNames,
"AllLangs": translation.AllLangs(),
"PageStartTime": startTime,

Expand Down
3 changes: 3 additions & 0 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ export function checkAppUrl() {
if (curUrl.startsWith(appUrl)) {
return;
}
if (document.querySelector('.page-content.install')) {
return; // no need to show the message on the installation page
}
showGlobalErrorMessage(`Your ROOT_URL in app.ini is ${appUrl} but you are visiting ${curUrl}
You should set ROOT_URL correctly, otherwise the web may not work correctly.`);
}

0 comments on commit 5b74660

Please sign in to comment.