mirror of
https://github.com/cita-777/metapi.git
synced 2026-11-02 21:38:32 +08:00
16 lines
484 B
TypeScript
16 lines
484 B
TypeScript
type ProxyEnv = Record<string, string | undefined>;
|
|
|
|
function normalizeTarget(raw: string): string {
|
|
return raw.trim().replace(/\/+$/, '');
|
|
}
|
|
|
|
export function resolveDevProxyTarget(env: ProxyEnv): string {
|
|
const explicit = normalizeTarget(env.DEV_PROXY_TARGET || env.VITE_DEV_PROXY_TARGET || '');
|
|
if (explicit) return explicit;
|
|
|
|
const port = (env.PORT || env.VITE_BACKEND_PORT || '').trim();
|
|
if (port) return `http://localhost:${port}`;
|
|
|
|
return 'http://localhost:4000';
|
|
}
|