CoastalCommitsPastes/client/lib/api-middleware/with-methods.ts

13 lines
383 B
TypeScript

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