Add helpers and types for BFF API
This commit is contained in:
parent
d626c2a498
commit
9dbd93a430
5 changed files with 89 additions and 0 deletions
16
lib/api/cmFetch.ts
Normal file
16
lib/api/cmFetch.ts
Normal 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();
|
||||
}
|
||||
Loading…
Reference in a new issue