feat: add proxy to url shortner
This commit is contained in:
-37
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user