Comments (4)
I didn't had time yet to investigate this.
I'm open to PR's that help fixing this, and yes i think we can merge #1 as it is a typo, even if it does not fix this problem.
If you want @willcosgrove re-open it and i'll merge it
from gatsby-plugin-netlify-functions.
I'm not entirely sure of the specifics of the lambda implementation, but is this a case of just adding certain body-parser
configuration?
const bodyParser = require('body-parser')
exports.onCreateDevServer = (
{ app },
{ ... snip }
) => {
app.use('/.netlify/functions/', bodyParser.text({ type: req => true }), (req, res, next) => {
//... snip
})
}
The example lambda functions I've seen seem to expect a text body (as opposed to parsing "application/json" or "application/x-www-form-urlencoded" automatically), then perform the parsing in the handler, like so:
exports.handler = function(event, context, callback) {
const data = JSON.parse(event.body)
// ... do something with data
}
Which seems to be backed up by https://www.netlify.com/docs/functions/, indicating the body should be a string in their example:
{
...
"body": "A JSON string of the request payload."
}
PS: The typo highlighted in #1 would still need to be fixed too I think i.e. res.body
should be req.body
.
EDIT: Oops. I didn't look at the correct branch on @willcosgrove's fork and missed the code for his actual changes. Sorry! His fork works well enough at least for the handling text (json) content.
from gatsby-plugin-netlify-functions.
Yes you are correct, and that would probably cover most people’s use cases. So that definitely seems like the right first step. But to fix it comprehensively, we would also need to handle non text bodies, like image data or something. It appears that in those cases, the lambda event should convert the body to a base64 encoding, and set a flag to indicate that the request body is base64 encoded.
I can’t find documentation on determining which requests will get base64 encoded. I believe that on AWS, that setup is configured in the API Gateway service, and not in Lambda. So it would depend on how Netlify has the API Gateway configured.
from gatsby-plugin-netlify-functions.
+1 upvote
from gatsby-plugin-netlify-functions.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-plugin-netlify-functions.