Skip to content
This repository has been archived by the owner on Dec 22, 2019. It is now read-only.

Fix request body in lambda event #1

Merged
merged 1 commit into from
Oct 30, 2018

Conversation

willcosgrove
Copy link
Contributor

@willcosgrove willcosgrove commented Oct 24, 2018

Thanks for building this awesome plugin! It's been really useful. I noticed, as I was writing a function that takes a request body, that the request body is not available in the lambda event. It was just a typo, grabbing the body from the res instead of the req. 馃槃 Took me a while of staring at it to figure out what was going on.

@willcosgrove
Copy link
Contributor Author

I'm closing this, because as I worked more on this I discovered this is not a complete fix.

The req.body still does not exist because there is no middleware consuming the body from the network socket. I have a fork which adds the body-parser library and adds the text parser middleware to the chain. But it is not a complete solution, because there's no handling of non text encoded bodies, like things that would get converted to base64 in the lambda environment.

If anyone else is running into this issue, you're welcome to use my branch which is probably fine for most use cases. It just doesn't handle base64 encoding non-text encoded bodies.

yarn add gatsby-plugin-netlify-functions@willcosgrove/gatsby-plugin-netlify-functions#body-fix

or change the version in your package.json like this:

"gatsby-plugin-netlify-functions": "willcosgrove/gatsby-plugin-netlify-functions#body-fix"

@porfirioribeiro
Copy link
Owner

Thanks for reporting this error and trying to fix it.
I will try to have a look later and find a way to fix it

@willcosgrove willcosgrove reopened this Oct 30, 2018
@porfirioribeiro porfirioribeiro merged commit bbb89bc into porfirioribeiro:master Oct 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants