File size: 874 Bytes
fbad523 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /**
* API configuration for ir-studio.
* Supports configurable VITE_API_URL for production deployments where frontend
* and backend are hosted on separate domains or subpaths.
*/
// If VITE_API_URL is provided (e.g. "https://api.ir-studio.org" or "http://backend:8000"),
// use it without trailing slash. Otherwise default to "" for same-origin relative URLs.
const rawApiUrl = (import.meta.env.VITE_API_URL as string | undefined)?.trim() || '';
export const API_BASE_URL = rawApiUrl.replace(/\/+$/, '');
/**
* Returns a fully qualified or relative URL for a given API endpoint.
*
* Example:
* apiUrl('/api/health') => "/api/health" (default) or "https://api.my-domain.com/api/health"
*/
export function apiUrl(endpoint: string): string {
const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
return `${API_BASE_URL}${cleanEndpoint}`;
}
|