first commit

This commit is contained in:
Mateusz Gruszczyński
2026-03-04 15:21:03 +01:00
commit 5429f176c9
53 changed files with 3808 additions and 0 deletions

26
frontend/lib/api.ts Normal file
View File

@@ -0,0 +1,26 @@
export const API_BASE = process.env.NEXT_PUBLIC_API_BASE || "http://localhost:8000";
export const WS_BASE = process.env.NEXT_PUBLIC_WS_BASE || "ws://localhost:8000";
export async function apiFetch(path: string, opts: RequestInit = {}) {
const res = await fetch(`${API_BASE}${path}`, {
...opts,
credentials: "include",
headers: {
...(opts.headers || {}),
"Content-Type": "application/json"
}
});
if (!res.ok) {
const txt = await res.text().catch(() => "");
throw new Error(txt || `HTTP ${res.status}`);
}
const ct = res.headers.get("content-type") || "";
if (ct.includes("application/json")) return res.json();
return res.text();
}
export function getCsrfFromCookie(): string | null {
if (typeof document === "undefined") return null;
const m = document.cookie.match(/(?:^|; )mt_csrf=([^;]+)/);
return m ? decodeURIComponent(m[1]) : null;
}