next-connect
next-connect copied to clipboard
How can I handle same method twice?
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.
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) {...}