taxonomy/lib/api-middlewares/with-methods.ts
2022-10-26 17:18:06 +04:00

11 lines
339 B
TypeScript

import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next"
export function withMethods(methods: string[], handler: NextApiHandler) {
return async function (req: NextApiRequest, res: NextApiResponse) {
if (!methods.includes(req.method)) {
return res.status(405).end()
}
return handler(req, res)
}
}