-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next JS Api Routes - POST - Invalid Body response with request body payload #715
Comments
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:
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. |
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
|
I saw that example, but I was unsure how to access 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 |
Encountered the same in NextJS 13. vercel/next.js#24894 (comment) helped resolve this issue for me. |
Prerequisites
Fastify version
4.15.0
Plugin version
9.2.0
Node.js version
18.14.2
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.2.1
Description
I'm trying to create a NextJS API Route for a POST method and send a payload. I can get regular page routes to work fine, even an API route with a GET method, works fine. I can also get a regular POST API Route to work, without a payload being sent
I created a API route located here: /src/pages/api/user.js ... This is based on the example located here: https://github.com/fastify/fastify-nextjs/blob/master/pages/api/user.js
I then updated my start file with the following:
When I open Post Man and try to send a POST request with the payload:
the response I get is a 400 with "Invalid body" message.
I put together a SandBox located here:
https://codesandbox.io/s/lucid-rumple-ceetg2?file=/src/start.js:128-261
Steps to Reproduce
Expected Behavior
Expected behavior is a NextJS API route should handle a POST just like it does in NextJS. Am I doing something wrong?
The text was updated successfully, but these errors were encountered: