next-connect icon indicating copy to clipboard operation
next-connect copied to clipboard

How can I handle same method twice?

Open GHCMelo opened this issue 2 years ago • 3 comments

Like:

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

Is that possible?

GHCMelo avatar Jan 18 '23 00:01 GHCMelo

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.

mtbrault avatar Jan 20 '23 11:01 mtbrault

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

kifah1989 avatar Feb 01 '23 12:02 kifah1989

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

silvaezequias avatar Feb 21 '24 02:02 silvaezequias