Comments (4)
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.
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.
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.
Encountered the same in NextJS 13. vercel/next.js#24894 (comment) helped resolve this issue for me.
from fastify-nextjs.
Related Issues (20)
- Update to latest Next.js HOT 18
- Update to Fastify v4 HOT 6
- Would be interested in seeing some sort of benchmarks (@fastify/nextjs) HOT 5
- fastify.next() is not a function HOT 5
- Remove package-lock, 2nd try
- Getting FastifyDeprecation: Modifying the "reply.sent" property is deprecated. Use the "reply.hijack()" method instead. HOT 2
- There is no host in the middleware of nextjs HOT 1
- Can you add an example for Assets serving in the readme ? HOT 7
- Does not work with fastify-cli typescript template HOT 14
- nextjs plugin trying to get /_next/webpack-hmr and has no current response HOT 1
- Fastify inject method instead of fetch or axios HOT 2
- Does the fastify-nextjs public folder not work as designed by NextJS? HOT 3
- fastify.inject timeout when @fastify/nextjs is registered HOT 4
- Throw error when use with [email protected] HOT 1
- drop node 14 support?! HOT 6
- How to implement ssr cache in next.js 13 HOT 1
- In Jest tests, when closing fastify/nextjs (app.close()), nextjs does not close
- fastify-nextjs with app router in next.js HOT 1
- Support Next.js v14 HOT 3
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 fastify-nextjs.