You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
809 B
22 lines
809 B
import { useRuntimeConfig } from '#imports';
|
|
|
|
const getBasePath = (): string => {
|
|
try {
|
|
const config = useRuntimeConfig();
|
|
return config.public.basePath;
|
|
} catch (e) {
|
|
console.error('Error getting base path:', e);
|
|
return process.env.NODE_ENV === 'production' ? process.env.BASE_PATH || '/' : '/';
|
|
}
|
|
};
|
|
|
|
|
|
export const withBasePath = (path: string): string => {
|
|
if (path.startsWith('http://') || path.startsWith('https://')) {return path;}
|
|
const currentBasePath = getBasePath();
|
|
if (!currentBasePath || path === '') {return path;}
|
|
if (path.startsWith(currentBasePath)) {return path;}
|
|
if (path.startsWith('~/')) {return path;}
|
|
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
return `${currentBasePath}${normalizedPath}`;
|
|
}; |