Improve AppUrl/ROOT_URL checking (#22836)
After some PRs: * #21986 * #22795 * #22808 * #22831 * #22839 Users won't be affected by the ROOT_URL problem in most cases. Close #19345 This PR improves AppUrl/ROOT_URL checking, only check it on the admin page, and the message is also updated. Feel free to suggest about more English-native messages. 
This commit is contained in:
		
					parent
					
						
							
								e253888a0e
							
						
					
				
			
			
				commit
				
					
						cef8f50286
					
				
			
		
					 3 changed files with 8 additions and 8 deletions
				
			
		| 
						 | 
					@ -1,12 +1,17 @@
 | 
				
			||||||
import $ from 'jquery';
 | 
					import $ from 'jquery';
 | 
				
			||||||
 | 
					import {checkAppUrl} from '../common-global.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const {csrfToken} = window.config;
 | 
					const {csrfToken} = window.config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function initAdminCommon() {
 | 
					export function initAdminCommon() {
 | 
				
			||||||
  if ($('.admin').length === 0) {
 | 
					  if ($('.page-content.admin').length === 0) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // check whether appUrl(ROOT_URL) is correct, if not, show an error message
 | 
				
			||||||
 | 
					  // only admin pages need this check because most templates are using relative URLs now
 | 
				
			||||||
 | 
					  checkAppUrl();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // New user
 | 
					  // New user
 | 
				
			||||||
  if ($('.admin.new.user').length > 0 || $('.admin.edit.user').length > 0) {
 | 
					  if ($('.admin.new.user').length > 0 || $('.admin.edit.user').length > 0) {
 | 
				
			||||||
    $('#login_type').on('change', function () {
 | 
					    $('#login_type').on('change', function () {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -381,9 +381,6 @@ export function checkAppUrl() {
 | 
				
			||||||
  if (curUrl.startsWith(appUrl) || `${curUrl}/` === appUrl) {
 | 
					  if (curUrl.startsWith(appUrl) || `${curUrl}/` === appUrl) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (document.querySelector('.page-content.install')) {
 | 
					  showGlobalErrorMessage(`Your ROOT_URL in app.ini is "${appUrl}", it's unlikely matching the site you are visiting.
 | 
				
			||||||
    return; // no need to show the message on the installation page
 | 
					Mismatched ROOT_URL config causes wrong URL links for web UI/mail content/webhook notification.`);
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  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.`);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,6 @@ import {
 | 
				
			||||||
  initCommitStatuses,
 | 
					  initCommitStatuses,
 | 
				
			||||||
} from './features/repo-commit.js';
 | 
					} from './features/repo-commit.js';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  checkAppUrl,
 | 
					 | 
				
			||||||
  initFootLanguageMenu,
 | 
					  initFootLanguageMenu,
 | 
				
			||||||
  initGlobalButtonClickOnEnter,
 | 
					  initGlobalButtonClickOnEnter,
 | 
				
			||||||
  initGlobalButtons,
 | 
					  initGlobalButtons,
 | 
				
			||||||
| 
						 | 
					@ -199,5 +198,4 @@ $(document).ready(() => {
 | 
				
			||||||
  initUserAuthWebAuthnRegister();
 | 
					  initUserAuthWebAuthnRegister();
 | 
				
			||||||
  initUserSettings();
 | 
					  initUserSettings();
 | 
				
			||||||
  initViewedCheckboxListenerFor();
 | 
					  initViewedCheckboxListenerFor();
 | 
				
			||||||
  checkAppUrl();
 | 
					 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue