Frontend/25_02_24/node_modules/@tinyhttp/send/dist/json.js

18 lines
604 B
JavaScript
Raw Normal View History

2025-02-25 08:55:29 +00:00
/**
* Respond with stringified JSON object
* @param res Response
*/
export const json = (res) => (body, ...args) => {
res.setHeader('Content-Type', 'application/json');
if ((typeof body === 'number' || typeof body === 'boolean' || typeof body === 'object') && body != null)
res.end(JSON.stringify(body, null, 2), ...args);
else if (typeof body === 'string')
res.end(body, ...args);
else {
res.removeHeader('Content-Length');
res.removeHeader('Transfer-Encoding');
res.end(null, ...args);
}
return res;
};
//# sourceMappingURL=json.js.map