You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export async function middleware(req: NextRequest) {
if (req.method !== 'POST') {
return error('POST only...');
}
const body = await req.json().catch((err) => {
console.log('token json', err);
});
console.log({ body });
// etc...
}
This logs out:
token json TypeError: invalid json body reason: Unexpected end of JSON input
at NextRequestHint.json (evalmachine.<anonymous>:172:19)
at async Object.middleware [as handler] (webpack-internal:///./src/pages/api/token/_middleware.ts:50:16)
at async adapter (webpack-internal:///../../node_modules/next/dist/server/web/adapter.js:30:22)
at async DevServer.runMiddleware (/Users/me/app/node_modules/next/dist/server/next-server.js:448:26)
at async DevServer.runMiddleware (/Users/me/app/node_modules/next/dist/server/dev/next-dev-server.js:400:28)
at async Object.fn (/Users/me/app/node_modules/next/dist/server/next-server.js:827:34)
at async Router.execute (/Users/me/app/node_modules/next/dist/server/router.js:222:32)
at async DevServer.run (/Users/me/app/node_modules/next/dist/server/next-server.js:1135:29)
at async DevServer.run (/Users/me/app/node_modules/next/dist/server/dev/next-dev-server.js:445:20)
at async DevServer.handleRequest (/Users/me/app/node_modules/next/dist/server/next-server.js:325:20)
{ body: undefined }
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.7
What version of Node.js are you using?
14 LTS
What browser are you using?
Firefox
What operating system are you using?
Mac 12.1
How are you deploying your application?
locally
Describe the Bug
I have a
_middleware.ts
file:This logs out:
By calling:
Expected Behavior
{ test: 1 }
should be returned fromawait req.json()
To Reproduce
Create a basic middleware as outlined above and call it with the basic curl command.
The text was updated successfully, but these errors were encountered: