14 lines
332 B
TypeScript
14 lines
332 B
TypeScript
// lib/json.ts
|
|
export function json(data: unknown, init?: ResponseInit) {
|
|
return new Response(
|
|
JSON.stringify(data, (_k, v) => (typeof v === "bigint" ? v.toString() : v)),
|
|
{
|
|
...init,
|
|
headers: {
|
|
"content-type": "application/json; charset=utf-8",
|
|
...(init?.headers || {}),
|
|
},
|
|
},
|
|
);
|
|
}
|