You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Drift/client/lib/api-middleware/with-methods.ts

14 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)
}
}