15 lines
516 B
TypeScript
15 lines
516 B
TypeScript
export const getPublicBaseUrl = (): string => {
|
|
const raw = (import.meta as any).env?.VITE_PUBLIC_BASE_URL as string | undefined;
|
|
if (!raw) return '';
|
|
return raw.replace(/\/$/, '');
|
|
};
|
|
|
|
export const resolvePublicUrl = (path?: string): string | null => {
|
|
if (!path) return null;
|
|
// If already absolute, return as-is.
|
|
if (/^https?:\/\//i.test(path)) return path;
|
|
|
|
const base = getPublicBaseUrl();
|
|
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
return `${base}${normalizedPath}`;
|
|
};
|