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.62k stars 65 forks source link

How can I handle same method twice? #219

Open GHCMelo opened 1 year ago

GHCMelo commented 1 year ago

Like:

export default nextConnect({
    attachParams: true,
})
.post(postHandlerOne)
.post(postHandlerTwo)

Is that possible?

mtbrault commented 1 year ago

What is your expected behavior with this code ? You are giving 2 differents handler for the same endpoint, I think that it will only consider the last handler given.

kifah1989 commented 1 year ago

create a new file in the api for a different post request.

silvaezequias commented 4 months ago

Like:

export default nextConnect({
    attachParams: true,
})
.post(postHandlerOne)
.post(postHandlerTwo)

Is that possible?

Yes, this is possible:

export default nextConnect({ attachParams: true })
 .post(postHandleOne)
 .post(postHandleTwo)

function postHandleOne(req, res, next) {
  // ... your handle code here
  next();
}

function postHandleTwo(req, res) {...}