/** Base URL for API calls. In dev Vite proxies /api → :3000. */ const BASE = ''; async function request(path: string, init?: RequestInit): Promise { const res = await fetch(BASE + path, { headers: { 'Content-Type': 'application/json', ...(init?.headers ?? {}) }, ...init, }); if (!res.ok) { const text = await res.text().catch(() => res.statusText); throw new Error(text || `HTTP ${res.status}`); } return res.json() as Promise; } export const api = { get: (path: string) => request(path), post: (path: string, body?: unknown) => request(path, { method: 'POST', body: body !== undefined ? JSON.stringify(body) : undefined }), patch: (path: string, body?: unknown) => request(path, { method: 'PATCH', body: body !== undefined ? JSON.stringify(body) : undefined }), delete: (path: string) => request(path, { method: 'DELETE' }), /** POST multipart/form-data (file upload). Omit Content-Type so browser sets boundary. */ postForm: (path: string, body: FormData) => request(path, { method: 'POST', body, headers: {} }), };