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.
16 lines
635 B
16 lines
635 B
import { useRuntimeConfig } from '#imports';
|
|
|
|
const getBasePath = (): string => {
|
|
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}`;
|
|
}; |