chore: add client/src/lib/queryClient.ts

This commit is contained in:
notshop 2026-04-26 16:35:04 +00:00
parent 4c415f02d1
commit 18a24c733d

View file

@ -0,0 +1,24 @@
import { QueryClient } from "@tanstack/react-query";
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 1,
staleTime: 30_000,
},
},
});
export async function apiRequest(method: string, path: string, body?: unknown): Promise<Response> {
const res = await fetch(path, {
method,
headers: body ? { "Content-Type": "application/json" } : {},
body: body ? JSON.stringify(body) : undefined,
credentials: "include",
});
if (!res.ok) {
const text = await res.text().catch(() => res.statusText);
throw new Error(text || `HTTP ${res.status}`);
}
return res;
}