added doga
This commit is contained in:
18
25_02_24/node_modules/@tinyhttp/send/dist/json.js
generated
vendored
Normal file
18
25_02_24/node_modules/@tinyhttp/send/dist/json.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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
|
||||
Reference in New Issue
Block a user