Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Last active June 19, 2017 22:57
Show Gist options
  • Save vinicius73/0556e3ff0acd1e5d273459b3786ef919 to your computer and use it in GitHub Desktop.
Save vinicius73/0556e3ff0acd1e5d273459b3786ef919 to your computer and use it in GitHub Desktop.
const Joi = require('joi')
const ensureJoiSchema = schema => (req, res, next) => {
Joi.validate(req.body, schema, (err, value) => {
if (err) {
res.json(err, 400)
next(false)
return
}
req.$requestData = value
next()
})
}
module.exports = ensureJoiSchema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment