Skip to content

Instantly share code, notes, and snippets.

@aaronshaf
Created September 9, 2016 20:36
Show Gist options
  • Save aaronshaf/e81d296a725f509dcf29bcd39d5df705 to your computer and use it in GitHub Desktop.
Save aaronshaf/e81d296a725f509dcf29bcd39d5df705 to your computer and use it in GitHub Desktop.
const Ajv = require('ajv')
const ajv = Ajv()
module.exports = function (schema) {
const validate = ajv.compile(schema)
return (req, res, next) => {
const isValid = validate(res.body)
if (!isValid) {
console.log('invalid list response', validate.errors)
res.status(500)
} else {
res.status(res.statusCode || 200).json(res.body)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment