From 4fd125ddfc0aeee589976e7314ddd5f05be00ec2 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 19 Oct 2023 16:48:50 +0300 Subject: [PATCH] base url support index file --- client/src/ajax.js | 2 +- client/src/app.js | 2 +- client/src/loader.js | 10 +++++++++- client/src/utils.js | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/client/src/ajax.js b/client/src/ajax.js index 793eedd67d..a80cf5670c 100644 --- a/client/src/ajax.js +++ b/client/src/ajax.js @@ -62,7 +62,7 @@ let onTimeout; * @property {boolean} [resolveWithXhr] To resolve with `XMLHttpRequest`. */ -const baseUrl = window.location.origin + window.location.pathname; +const baseUrl = Espo.Utils.obtainBaseUrl(); // noinspection JSUnusedGlobalSymbols /** diff --git a/client/src/app.js b/client/src/app.js index d586957f7d..0392d961b0 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -1442,7 +1442,7 @@ class App { files.push(file); }); - let baseUrl = window.location.origin + window.location.pathname; + let baseUrl = Espo.Utils.obtainBaseUrl(); let timestamp = this.loader.getCacheTimestamp(); let promiseList = files.map(file => { diff --git a/client/src/loader.js b/client/src/loader.js index 749dcab685..14eeeb71cf 100644 --- a/client/src/loader.js +++ b/client/src/loader.js @@ -99,7 +99,15 @@ this._internalModuleMap = {}; this._isDeveloperMode = false; - this._baseUrl = window.location.origin + window.location.pathname; + let baseUrl = window.location.origin + window.location.pathname; + + if (baseUrl.slice(-1) !== '/') { + baseUrl = window.location.pathname.includes('.') ? + baseUrl.slice(0, baseUrl.lastIndexOf('/')) + '/' : + baseUrl + '/'; + } + + this._baseUrl = baseUrl; this._isDeveloperModeIsSet = false; this._basePathIsSet = false; diff --git a/client/src/utils.js b/client/src/utils.js index 4a0cd390aa..4b90ee77eb 100644 --- a/client/src/utils.js +++ b/client/src/utils.js @@ -662,6 +662,23 @@ Espo.Utils = { generateId: function () { return (Math.floor(Math.random() * 10000001)).toString() }, + + /** + * Not to be used in custom code. Can be removed in future versions. + * @internal + * @return {string} + */ + obtainBaseUrl: function () { + let baseUrl = window.location.origin + window.location.pathname; + + if (baseUrl.slice(-1) !== '/') { + baseUrl = window.location.pathname.includes('.') ? + baseUrl.slice(0, baseUrl.lastIndexOf('/')) + '/' : + baseUrl + '/'; + } + + return baseUrl; + } }; const keyMap = {