Fix LAN API base and development CORS regression
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user