divan/web/src/lib/api.ts
Anas Rashid 60f0791405 Divan v2: Astro site with Divan's own design (proof of concept)
- web/: server-rendered Astro over the Node API: home (poets by Hijri century), poet
  (intro + sections), category (numbered contents), poem (couplets, prev/next, source),
  search (paged); Naskh default with Nastaliq toggle, light/dark, Urdu digits, RTL, mobile
- api: section counts include nested categories
- README: how to run v2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 20:26:54 +02:00

10 lines
380 B
TypeScript

// Divan API client (server-side; API_URL defaults to the local API)
const API = process.env.API_URL ?? 'http://127.0.0.1:4100';
export async function api<T = any>(path: string): Promise<T | null> {
const res = await fetch(API + path);
if (res.status === 404) return null;
if (!res.ok) throw new Error(`API ${res.status} for ${path}`);
return res.json() as Promise<T>;
}