feat: default web API calls to same origin

This commit is contained in:
2026-05-01 08:35:06 +09:00
parent 7cfd50532d
commit 8656f237d4
7 changed files with 59 additions and 9 deletions

View File

@@ -0,0 +1,22 @@
const LOCALHOST_API_ORIGIN = 'http://localhost:3001';
function trimTrailingSlashes(value: string): string {
return value.replace(/\/+$/, '');
}
export function getApiBaseUrl(
configuredApiBaseUrl?: string,
windowOrigin?: string,
): string {
const configured = configuredApiBaseUrl?.trim();
if (configured) {
return trimTrailingSlashes(configured);
}
const origin = windowOrigin?.trim();
if (origin) {
return trimTrailingSlashes(origin);
}
return LOCALHOST_API_ORIGIN;
}