serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

Request body is empty - awsServerlessExpress.proxy eats up event body

Open ethoman opened this issue 6 years ago • 2 comments

I have tried everything - I have set headers to application json, I have used body parser - nothing works.

const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);    
exports.handler = (event, context) => {
  console.log(event); // Has event body
      awsServerlessExpress.proxy(server, event, context); // Does not have event body
};

Why is this eating up event.body? This is an issue that has plagued this library for so long and there are posts about it every week. Can someone please offer some guidance here? I may have to switch libraries and potentially stop using Claudiajs just because of this issue.

ethoman avatar Nov 25 '20 22:11 ethoman

@ethoman I had the same problem when I run the lambda local with a event.json. In my case, I had to add the following header: Content-Type: application/json to let express (and body-parser bodyParser.json()) parse the body.

{
  "httpMethod": "POST",
  "path": "/my-url",
  "body": "{"email\": \"[email protected]\"}",
  "headers": {
    "Content-Type": "application/json"
  }
}

kaldebert avatar Dec 10 '20 08:12 kaldebert

Thanks @kaldebert. @ethoman does this solve your issue?

brettstack avatar Dec 15 '20 02:12 brettstack