16 lines
388 B
TypeScript
16 lines
388 B
TypeScript
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();
|
|
}
|