mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
|
export const getBasePathGenerator = () => {
|
||
|
let basePath: string | undefined;
|
||
|
const DEFAULT = '::baseUriPath::';
|
||
|
|
||
|
return () => {
|
||
|
if (process.env.NODE_ENV === 'development') {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
if (basePath !== undefined) {
|
||
|
return basePath;
|
||
|
}
|
||
|
const baseUriPath = document.querySelector<HTMLMetaElement>(
|
||
|
'meta[name="baseUriPath"]'
|
||
|
);
|
||
|
|
||
|
if (baseUriPath?.content) {
|
||
|
basePath = baseUriPath?.content;
|
||
|
|
||
|
if (basePath === DEFAULT) {
|
||
|
basePath = '';
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
return basePath;
|
||
|
}
|
||
|
basePath = '';
|
||
|
return basePath;
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export const getBasePath = getBasePathGenerator();
|
||
|
|
||
|
export const formatApiPath = (path: string) => {
|
||
|
const basePath = getBasePath();
|
||
|
|
||
|
if (basePath) {
|
||
|
return `${basePath}/${path}`;
|
||
|
}
|
||
|
return `/${path}`;
|
||
|
};
|
||
|
|
||
|
export const formatAssetPath = (path: string) => {
|
||
|
const basePath = getBasePath();
|
||
|
|
||
|
if (basePath) {
|
||
|
return `${basePath}/${path}`;
|
||
|
}
|
||
|
|
||
|
return path;
|
||
|
};
|