aws-lambda-router
aws-lambda-router copied to clipboard
Pass rawBody instead of parsed
I customized this module locally and added a jsonParse flag to the routes so that I can have the option to parse or not parse a JSON event body. Since I don't know typescript I can't do a pull request on your code but this is a very quick to add and useful feature.
example route:
routes: [
{
path: '/somepath',
method: 'POST',
action: async (event) => {
//some function
};
return response;
},
jsonParse: true
}
]
code change (javascript proxyIntegration.js line 80):
if (event.body && actionConfig.jsonParse) {
try {
proxyEvent.body = JSON.parse(event.body);
} catch (parseError) {
console.log(`Could not parse body as json: ${event.body}`, parseError);
return {
statusCode: 400,
headers,
body: JSON.stringify({ message: 'body is not a valid JSON', error: 'ParseError' }),
};
}
} else proxyEvent.body = event.body;