feat: add base url utility and update api endpoints

This commit is contained in:
2025-11-11 11:27:56 +08:00
parent 21d46e7440
commit a606b5766a
12 changed files with 44 additions and 15 deletions

View File

@@ -0,0 +1,24 @@
export const getBaseUrl = (): string => {
const url = process.env.UMI_APP_API_BASE_URL || '';
return url.replace(/\/+$/, '');
};
const isAbsoluteUrl = (u: string): boolean => {
if (!u) return false;
const lower = u.toLowerCase();
return (
lower.startsWith('http://') ||
lower.startsWith('https://') ||
lower.startsWith('data:') ||
lower.startsWith('blob:')
);
};
export const withBaseUrl = (input: string): string => {
if (!input) return input;
if (isAbsoluteUrl(input)) return input;
const base = getBaseUrl();
if (!base) return input;
if (input.startsWith('/')) return `${base}${input}`;
return `${base}/${input}`;
};