Skip to content

Commit a85ab64

Browse files
committed
fix: correctly handle base64 encoded message body (ApiGateway)
1 parent 4c41379 commit a85ab64

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ module.exports.serverless = appFn => {
4949
const headers = lowerCaseKeys(event.headers)
5050
const e = headers['x-github-event']
5151

52+
// If body is expected to be base64 encoded, decode it and continue
53+
if (event.isBase64Encoded) {
54+
event.body = Buffer.from(event.body, 'base64').toString('utf8')
55+
}
56+
5257
// Convert the payload to an Object if API Gateway stringifies it
5358
event.body = (typeof event.body === 'string') ? JSON.parse(event.body) : event.body
5459

0 commit comments

Comments
 (0)