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.

21 lines
799 B

import { useRuntimeConfig } from '#imports';
const getBasePath = (): string => {
try {
const config = useRuntimeConfig();
return config.public.basePath || '';
} catch (e) {
return process.env.NODE_ENV === 'production' ? process.env.BASE_PATH || '/containers/matheothierry-portfolio_nuxt' : '';
}
};
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}`;
};