Add helpers and types for BFF API

This commit is contained in:
Hannah dagemark 2026-08-14 22:37:42 +02:00
commit 9dbd93a430
5 changed files with 89 additions and 0 deletions

16
lib/api/cmFetch.ts Normal file
View file

@ -0,0 +1,16 @@
import { RequestInit } from "next/dist/server/web/spec-extension/request";
const FRONTEND_URL = process.env.FRONTEND_URL;
export async function cmFetch<T>(
bffUrl: string | URL,
options?: RequestInit,
): Promise<T> {
const response = await fetch(`${FRONTEND_URL}/${bffUrl}`, options);
if (!response.ok) {
throw new Error("Request failed");
}
return response.json();
}