github codecoolture/next-joi v2.1.0

latest releases: v2.2.1, v2.2.0, v2.1.1...
3 years ago

✨ New

The validation function has now support to check the headers property from the incoming request!

import Joi from "joi";
import withJoi from "next-joi";

const validate = withJoi({
  onValidationError: (_, res) => {
    return res.status(400).end();
  },
});

export default validate(
  {
    headers: Joi.object({
      "accept-language": Joi.string().valid("en"),
    }).unknown(),
  },
  (req, res) => {
    // This function will be only executed if the incoming request complies
    // with the validation schema defined above.
  }
);

Don't miss a new next-joi release

NewReleases is sending notifications on new releases.