dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.73k stars 167 forks source link

unclear if PUT body is properly forwarded... not sure how to debug #256

Closed refacktor closed 1 year ago

refacktor commented 1 year ago

I'm trying to use serverless-http to create a serverless deployment of pouchdb-server on top of AWS Lambda with Elastic Filesystem.

My solution is here: https://github.com/refacktor/pouchdb-aws-serverless

I'm currently able to get the standard PouchDB response with a curl -X GET ... and was able to create a database by using curl -X PUT https://.../db1.

But when I try to PUT a document with:

curl -X PUT https://XXXXXXXXX.execute-api.us-west-2.amazonaws.com/prod/db1/doc1 -d '{"hello":"world", "_id":"doc1"}' I get: {"error":"missing_id","reason":"_id is required for puts"}

My best guess here is that the PUT body is not getting forwarded by serverless-http, but I'm unsure how to troubleshoot further.

dougmoscrop commented 1 year ago

The first thing I'd check is whether or not a proper Content-Type header is required so that the express-pouchdb component knows the body is JSON, otherwise it's just getting the actual string {"hello":...

You could of course force it to assume the request is always json by using a request transformation assuming that is the issue!

refacktor commented 1 year ago

@dougmoscrop yes indeed, adding a -H "Content-Type: application/json" solves the problem! Although I don't fully understand why... we can close this issue. When using the component through normal http, the header is not required.