Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I handle same method twice? #219

Open
GHCMelo opened this issue Jan 18, 2023 · 3 comments
Open

How can I handle same method twice? #219

GHCMelo opened this issue Jan 18, 2023 · 3 comments

Comments

@GHCMelo
Copy link

GHCMelo commented Jan 18, 2023

Like:

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

Is that possible?

@mtbrault
Copy link

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
Copy link

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

@silvaezequias
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants