Fix LAN API base and development CORS regression

This commit is contained in:
2026-03-01 13:56:25 -03:00
parent bdd97d1c62
commit 48cfc79b5f
6 changed files with 45 additions and 5 deletions

View File

@@ -14,9 +14,25 @@ import type {
} from '../types';
/**
* Resolves backend base URL from environment with localhost fallback.
* Resolves backend base URL from environment with current-host HTTP fallback.
*/
const API_BASE = import.meta.env?.VITE_API_BASE ?? 'http://localhost:8000/api/v1';
function resolveApiBase(): string {
const envValue = import.meta.env?.VITE_API_BASE;
if (typeof envValue === 'string') {
const trimmed = envValue.trim().replace(/\/+$/, '');
if (trimmed) {
return trimmed;
}
}
if (typeof window !== 'undefined' && window.location?.hostname) {
return `http://${window.location.hostname}:8000/api/v1`;
}
return 'http://localhost:8000/api/v1';
}
const API_BASE = resolveApiBase();
/**
* Legacy environment token fallback used only when no runtime token source is available.