hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.64k stars 65 forks source link

how to order the response [onNoMatch] #188

Closed a7medmo7med9 closed 2 years ago

a7medmo7med9 commented 2 years ago

when i send request to post method with get method it works and i don't even use get method on this url

1

my code

2

how can i get 404 page not found on [onNoMatch] instead of this response

{
  "validationErrors": {
      "email": "This Field Is Required",
      "password": "This Field Is Required"
    }
}
hoangvvo commented 2 years ago

Currently, we are treating .use just as a handler. For now, you can add that middleware before the post handler like below:

.post(validateApiDate(loginSchema), async (req, res) =>

and remove the .use.

hoangvvo commented 2 years ago

Just to confirm that this is a valid error.

even if .use matches, since there is no .METHOD, nothing should be executed. Will be fixed in https://github.com/hoangvvo/next-connect/pull/196