const API_BASE = import.meta.env.VITE_API_BASE; const API_KEY = import.meta.env.VITE_API_KEY; export async function apiGet(path: string): Promise { console.log("API_BASE:", API_BASE); console.log("Calling:", `${API_BASE}${path}`); const response = await fetch(`${API_BASE}${path}`, { headers: { "X-API-Key": API_KEY, }, }); if (!response.ok) { throw new Error(`API error ${response.status}`); } return response.json(); } export async function apiPost( path: string, body: TBody ): Promise { const response = await fetch(`${API_BASE}${path}`, { method: "POST", headers: { "Content-Type": "application/json", "X-API-Key": API_KEY, }, body: JSON.stringify(body), }); if (!response.ok) { const error = await response.json().catch(() => null); throw new Error(error?.error || `API error ${response.status}`); } return response.json(); }