Giter Club home page Giter Club logo

Comments (4)

porfirioribeiro avatar porfirioribeiro commented on June 2, 2024 1

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.

davetransom avatar davetransom commented on June 2, 2024

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.

willcosgrove avatar willcosgrove commented on June 2, 2024

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.

DavidSabine avatar DavidSabine commented on June 2, 2024

+1 upvote

from gatsby-plugin-netlify-functions.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.