14 lines
515 B
TypeScript
14 lines
515 B
TypeScript
export const API_URL = process.env.NEXT_PUBLIC_API_URL ?? "https://localhost:7030";
|
|
|
|
export async function apiFetch<T>(path: string): Promise<T> {
|
|
const res = await fetch(`${API_URL}${path}`, { signal: AbortSignal.timeout(8000) });
|
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
|
return res.json() as Promise<T>;
|
|
}
|
|
|
|
export function assetUrl(path?: string | null): string | undefined {
|
|
if (!path) return undefined;
|
|
if (path.startsWith('http')) return path;
|
|
return `${API_URL}${path}`;
|
|
}
|