alagarr
Version:
Alagarr is a request-response helper library that removes the boilerplate from your Node.js serverless functions and helps make your code portable.
19 lines (18 loc) • 546 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const parseJson = (stringified) => {
try {
return JSON.parse(stringified);
}
catch (_a) {
return {};
}
};
function parseJsonBody(request) {
const { headers, body } = request;
return headers['content-type'] &&
headers['content-type'].split(';').shift() === 'application/json' &&
typeof body === 'string'
? Object.assign({}, request, { body: parseJson(body) }) : request;
}
exports.default = parseJsonBody;