bunshine
Version:
A Bun HTTP & WebSocket server that is a little ray of sunshine.
15 lines (13 loc) • 380 B
text/typescript
import Context from '../../Context/Context';
export default function json(
this: Context,
data: any,
init: ResponseInit = {}
) {
const body = JSON.stringify(data);
init.headers = new Headers(init.headers || {});
if (!init.headers.has('Content-Type')) {
init.headers.set('Content-Type', `application/json; charset=utf-8`);
}
return new Response(body, init);
}