// All backend calls go through this module. Components and routes import // the typed helpers below — they do not call fetch directly. const BASE = (typeof import.meta !== 'undefined' && import.meta.env?.VITE_API_BASE) || '/api'; export class ApiError extends Error { constructor( public readonly status: number, message: string ) { super(message); this.name = 'ApiError'; } } export async function request(path: string, init?: RequestInit): Promise { const res = await fetch(`${BASE}${path}`, init); if (!res.ok) { const text = await res.text().catch(() => ''); throw new ApiError(res.status, text || `${res.status} ${res.statusText}`); } return (await res.json()) as T; } export type Manga = { id: string; title: string; author: string | null; description: string | null; cover_image_path: string | null; created_at: string; updated_at: string; };