ppt-tool/frontend/lib/apiFetch.ts
Vadym Samoilenko 910f58369c Fix EventSource URLs missing /ppt-tool basePath
Add apiUrl() helper to apiFetch.ts for non-fetch URL construction.
Fixed 3 SSE streams: outlines, presentation, job progress.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 18:02:07 +00:00

18 lines
702 B
TypeScript

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