Makes the webpack build use relative paths to allow for deploying on web subdirectories
Some checks are pending
build-docker / Build Image (push) Waiting to run
Some checks are pending
build-docker / Build Image (push) Waiting to run
This commit is contained in:
parent
f77bcbadb7
commit
ea8c3bf602
10 changed files with 74 additions and 36 deletions
25
server/scripts/modules/utils/base-path.mjs
Normal file
25
server/scripts/modules/utils/base-path.mjs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
const normalizeBasePath = (pathname) => {
|
||||
if (!pathname) return '/';
|
||||
if (pathname.endsWith('/index.html')) {
|
||||
const trimmed = pathname.slice(0, -'index.html'.length);
|
||||
return trimmed.endsWith('/') ? trimmed : `${trimmed}/`;
|
||||
}
|
||||
if (pathname.endsWith('/')) return pathname;
|
||||
const lastSlash = pathname.lastIndexOf('/');
|
||||
if (lastSlash === -1) return '/';
|
||||
return `${pathname.slice(0, lastSlash + 1)}`;
|
||||
};
|
||||
|
||||
const getBasePath = () => normalizeBasePath(window.location.pathname);
|
||||
|
||||
const withBasePath = (relativePath = '') => {
|
||||
const sanitizedPath = relativePath.replace(/^\/+/, '');
|
||||
const basePath = getBasePath();
|
||||
if (basePath === '/') return `/${sanitizedPath}`;
|
||||
return `${basePath}${sanitizedPath}`;
|
||||
};
|
||||
|
||||
export {
|
||||
getBasePath,
|
||||
withBasePath,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue