feat: add base url utility and update api endpoints
This commit is contained in:
24
ragflow_web/src/utils/url.ts
Normal file
24
ragflow_web/src/utils/url.ts
Normal 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}`;
|
||||
};
|
||||
Reference in New Issue
Block a user