I want to create a piece of express middleware looks something like this:
function validate (options) {
var defaultOptions = {...}
, validations = _.extend(defaultOptions, options);
return validate (req, res, next) {
/* Use some sort of validation framework where I can pass `validations` into*/
next(someErrors || null)
}
}
I've looked at both node-validator with the middleware option as well as tracery but neither of them looked like you could pass a "rule set" into them and have them run the rules against a provided input.
Does anyone have any suggestions on how to do this with either of those modules or with another one that I haven't found yet? Am I going to have to roll my own to do this?
UPDATE
This is indeed to validate form posts. I know there won't be a single piece of middleware that will cover all of the posts for the whole site; this will be used only for certain routes. I want reusable middleware because we are making APIs that have common routes and expect common form bodies that we want to validate in similar fashion with the option to tweak that on a per API basis.