express.ts 318 B

123456789101112131415
  1. import * as express from 'express'
  2. const methodsValidator = (methods: string[]) => {
  3. return (req: express.Request, res: express.Response, next: express.NextFunction) => {
  4. if (methods.includes(req.method) !== true) {
  5. return res.sendStatus(405)
  6. }
  7. return next()
  8. }
  9. }
  10. export {
  11. methodsValidator
  12. }