/** * 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}`; }