Giter Site home page Giter Site logo

Comments (4)

matthewgisonno avatar matthewgisonno commented on June 1, 2024

Ok, following up here... I'm not sure this is actually a bug, but more of a "feature" of how fastify handles / parses data. After reviewing this document: https://www.fastify.io/docs/latest/Reference/ContentTypeParser/

I was able to fix the issue I was facing by killing all the content parsers and adding a generic parser. Like so:

  await app.register(fastifyNext, {}).after(async () => {
    app.removeAllContentTypeParsers();

    app.addContentTypeParser('*', function (request, payload, done) {
      done();
    });

    await app.next('/api/user', { method: 'POST' });
  });

Does this sound right or should this @fastify/nextjs plugin handle the POST method separately from the fastify server itself? Any feedback or comments wishing to explain further would be greatly appreciated.

from fastify-nextjs.

Eomm avatar Eomm commented on June 1, 2024

No, I don't think that is the right approach - at least it should not work with a paylod

I checked a bit without success, but I would investigate the interface instead

fastify.next('/hello', (app, req, reply) => {
  // your code
  // `app` is the Next instance
  app.render(req.raw, reply.raw, '/hello', req.query, {})
})

from fastify-nextjs.

matthewgisonno avatar matthewgisonno commented on June 1, 2024

I saw that example, but I was unsure how to access req.raw and if that is just overwriting the request that is being forwarded to the next server, it's still eating the payload, so req.body should be the payload I send in my POST to the API route, but it creates a 400 error - Invalid Body.

Also worth mentioning, NextJS out of the box handles a POST request to an API Route with a payload. So in a normal NextJS app, you can access req.body without issues.

from fastify-nextjs.

christmoore avatar christmoore commented on June 1, 2024

Encountered the same in NextJS 13. vercel/next.js#24894 (comment) helped resolve this issue for me.

from fastify-nextjs.

Related Issues (20)

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.