26 lines
965 B
TypeScript
26 lines
965 B
TypeScript
/** URL por defecto del API Gateway (dev: local Docker; instalador: pys1.builker.xyz). */
|
|
export const DEFAULT_API_BASE_URL: string = __DEFAULT_API_BASE_URL__;
|
|
|
|
/** Reemplaza localhost por 127.0.0.1 para evitar problemas de IPv6 en Windows/Docker. */
|
|
export function normalizeApiBaseUrl(url: string | null | undefined): string {
|
|
const raw = (url || DEFAULT_API_BASE_URL).trim();
|
|
return raw.replace(/:\/\/localhost\b/i, "://127.0.0.1");
|
|
}
|
|
|
|
export function loadApiBaseUrl(): string {
|
|
return normalizeApiBaseUrl(localStorage.getItem("apiBaseUrl"));
|
|
}
|
|
|
|
/** Migra localStorage si el usuario tenía localhost o el puerto antiguo 8000. */
|
|
export function migrateApiBaseUrlInStorage(): void {
|
|
const stored = localStorage.getItem("apiBaseUrl");
|
|
if (!stored) return;
|
|
let next = normalizeApiBaseUrl(stored);
|
|
if (next.includes(":8000")) {
|
|
next = next.replace(":8000", ":8189");
|
|
}
|
|
if (next !== stored) {
|
|
localStorage.setItem("apiBaseUrl", next);
|
|
}
|
|
}
|