-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Middleware in API have a null body on POST Requests #30953
Comments
That's because you can't use Edge Functions with We are working on it 🙂 |
Is there any update on this or an ETA when it will be fixed? 👀 |
I'm also having this middleware issue, but seems to be happening on all HTTP requests, not just |
Are these sorts of limitations documented anywhere? As excited as I am about middleware, it can be time consuming to diagnose whether we've done something wrong in our setup, or if it just isn't possible today This part of the documentation even strongly implies that this is possible: https://nextjs.org/docs/api-reference/next/server#why-does-redirect-use-307-and-308 |
I will tackle this ✋ |
Related: - resolves vercel#30953
This PR brings back @Schniz awesome contribution to bring in bodies to middleware. It was reverted to leave it out of the stable release and to have some time to test it out in canary before officially releasing it. This PR is simply a `cherry-pick` of his original work. Closes: #30953 Closes: #34490 Co-authored-by: Gal Schlezinger <[email protected]>
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
12.0.2
What version of Node.js are you using?
v14.18.0
What browser are you using?
Chrome
What operating system are you using?
Linux
How are you deploying your application?
next dev, next start, Vercel
Describe the Bug
When sending a POST request that gets handled by middleware in the /pages/api folder, the request body is always null.
So, in the client side (
/pages/index.tsx
) we have:In
/api/middlewaretest/_middleware.ts
we have:Expected Behavior
In https://nextjs.org/docs/api-reference/next/server#nextrequest it notes that
NextRequest
is an extension of the nativeRequest
interface which should provide a stream onreq.body
that could be read. However, it always comes across as null.To Reproduce
https://github.com/idreaminteractive/nextjs-middleware-body
yarn
yarn dev
(oryarn build && yarn start
)http://localhost:3000
Send the post
button to trigger the middleware, check the console logs to seereq.body
is always null for aPOST
request.The second button (Send the post to hello) is a regular NextJS API end point and works fine.
The text was updated successfully, but these errors were encountered: