feat: add proxy to url shortner

This commit is contained in:
gosangam
2026-05-11 17:28:04 +05:30
parent cc94296b46
commit 30d08c665d
3 changed files with 80 additions and 44 deletions
-37
View File
@@ -122,40 +122,3 @@ export async function bffList<T>(
return result ?? [];
}
/**
* POST JSON to the BFF API. Used for mutations like the URL shortener; does
* not participate in Next.js caching (each POST is a unique side-effect).
*
* Same envelope-unwrapping behavior as bff(): returns the inner `data`
* value, throws BffError on non-2xx.
*/
export async function bffPost<T>(
path: string,
body: Record<string, unknown>,
): Promise<T> {
const url = apiUrl(path);
const res = await fetch(url, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(body),
cache: "no-store",
});
if (!res.ok) {
const text = await res.text().catch(() => "");
throw new BffError(
res.status,
`BFF ${res.status} POST ${path}: ${text.slice(0, 200)}`,
);
}
const json = await res.json();
if (json && typeof json === "object" && "data" in json) {
return json.data as T;
}
return json as T;
}