18 lines
604 B
JavaScript
18 lines
604 B
JavaScript
/**
|
|
* 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
|