UNPKG

cloud-red

Version:

Harnessing Serverless for your cloud integration needs

27 lines (24 loc) 720 B
module.exports.eventContext = options => function apiGatewayEventParser(req, res, next) { if ( !req.headers['x-apigateway-event'] || !req.headers['x-apigateway-context'] ) { console.error( 'Missing x-apigateway-event or x-apigateway-context header(s)' ); next(); return; } req['x-cloudred-aws'] = { context: JSON.parse( decodeURIComponent(req.headers['x-apigateway-context']) ), event: JSON.parse(decodeURIComponent(req.headers['x-apigateway-event'])) }; // console.log(req); // remove the original headers delete req.headers['x-apigateway-event']; delete req.headers['x-apigateway-context']; next(); };