hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2

Home Page:https://www.npmjs.com/package/next-connect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I handle same method twice?

GHCMelo opened this issue · comments

Like:

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

Is that possible?

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.

commented

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

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) {...}