@nodesecure/cli
Version:
Node.js security CLI
20 lines (18 loc) • 354 B
JavaScript
/**
* @async
* @function bodyParser
* @param {*} req
* @returns {Promise<any>}
*/
export async function bodyParser(req) {
let rawBody = "";
for await (const chunk of req) {
rawBody += chunk;
}
switch (req.headers["content-type"]) {
case "application/json":
return JSON.parse(rawBody);
default:
return rawBody;
}
}