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:
app.register(require("@fastify/nextjs")).after(() => {
app.next("/hello");
app.next("/api/user", { method: "POST" });
});
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
- Create API route located here: /src/pages/api/user.js
- Update start.js for API route
- Restart server
- Make a POST request to your API route with a JSON body payload: http://localhost/api/user
- See 400 Invalid Body response
Expected Behavior
Expected behavior is a NextJS API route should handle a POST just like it does in NextJS. Am I doing something wrong?
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?