ppt-tool/frontend/lib/apiFetch.ts
Vadym Samoilenko bebe2ac390 Fix API routing: apiFetch helper prefixes basePath for all /api/v1/ calls
Without this, fetch('/api/v1/...') from the browser hits Apache root,
which routes /api/ to OliVAS (port 8000) instead of DeckForge (port 8001).
apiFetch prepends NEXT_PUBLIC_BASE_PATH so requests go through Next.js
rewrites to the correct backend.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 22:12:25 +00:00

12 lines
483 B
TypeScript

/**
* Wrapper around fetch that prepends the Next.js basePath so API calls
* reach the correct backend when deployed under a sub-path (e.g. /ppt-tool).
*
* Usage: apiFetch('/api/v1/...', options) — identical to fetch(), just works.
*/
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? '';
export function apiFetch(path: string, init?: RequestInit): Promise<Response> {
const url = path.startsWith('/api/') ? `${BASE_PATH}${path}` : path;
return fetch(url, init);
}