9 lines
394 B
TypeScript
Raw Normal View History

2025-09-16 00:05:16 -05:00
// frontend/src/api.ts
2025-09-08 00:48:47 -05:00
export async function api<T=any>(path: string, init?: RequestInit): Promise<T> {
const r = await fetch(path, { credentials:'include', ...init });
if (!r.ok) throw new Error(await r.text());
const ct = r.headers.get('content-type') || '';
return (ct.includes('json') ? r.json() : (r.text() as any)) as T;
}
export type WhoAmI = { username: string; root: string };