UNPKG

@mark01/express-utils

Version:

npm package that contains utilities for express.js

20 lines (19 loc) 443 B
import { AppError } from '../error'; export const xst = () => (req, _, next) => { const allowedMethods = [ 'OPTIONS', 'HEAD', 'CONNECT', 'GET', 'POST', 'PATCH', 'PUT', 'DELETE', ]; if (!allowedMethods.includes(req.method)) { next(new AppError(`Method ${req.method} is not allowed in this API!`, 405)); return; } next(); }; export default xst;