/** * Wrapper around fetch that prepends the Next.js basePath so API calls * reach the correct backend when deployed under a sub-path (/ppt-tool). * * Must match basePath in next.config.mjs. * Usage: apiFetch('/api/v1/...', options) — identical to fetch(), just works. */ const BASE_PATH = '/ppt-tool'; export function apiFetch(path: string, init?: RequestInit): Promise { const url = path.startsWith('/api/') ? `${BASE_PATH}${path}` : path; return fetch(url, init); } /** Returns the full URL with basePath — use for EventSource and other non-fetch calls. */ export function apiUrl(path: string): string { return path.startsWith('/api/') ? `${BASE_PATH}${path}` : path; }