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

fix next-connect integration #11

Closed

Conversation

beholderrk
Copy link

Condition with next

if (undefined !== next) {
    return next();
}

always triggered before handler. When next-connect used this behavior always return 404 status.

@sergioalvz
Copy link
Member

Hey there! Thanks for contributing. I have been using this package with next-connect for a long time with no issue. Please, create a test case that helps to validate the change. They are under the tests/ folder.

@sergioalvz sergioalvz assigned sergioalvz and unassigned sergioalvz Dec 29, 2021
@sualko
Copy link
Contributor

sualko commented Jan 24, 2022

@beholderrk I guess you are using this middleware like this:

connect().post(validate({ body: schema }, (req, res) => {
  // This function will be only executed if the incoming request complies
  // with the validation schema defined above.
})))

but you should not pass your handler to the validate function, instead you should pass your handler as second argument to the post function.

//.post( VALIDATE, HANDLER ) instead of .post( VALIDATE( HANDLER ))
connect().post(validate({ body: schema }), (req, res) => {
  // This function will be only executed if the incoming request complies
  // with the validation schema defined above.
}))

Therefore the precedence of the next call is irrelevant.

@beholderrk
Copy link
Author

@sualko ok thx! I'll try this.

@beholderrk beholderrk closed this Feb 4, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants