This commit is contained in:
Agusti Fernandez Pardo committed 2022-03-30 14:17:55 +02:00
1 parent 39ae2aed37
commit 1de7bc4146
126 files changed
+1240 -992

No files matched your search

+6 -8
View File
@@ -1,19 +1,17 @@
import { NextMiddleware } from "next-api-middleware";
export const httpMethod = (
allowedHttpMethod: "GET" | "POST" | "PATCH" | "DELETE"
): NextMiddleware => {
export const httpMethod = (allowedHttpMethod: "GET" | "POST" | "PATCH" | "DELETE"): NextMiddleware => {
return async function (req, res, next) {
if (req.method === allowedHttpMethod || req.method == "OPTIONS") {
await next();
} else {
res.status(404);
res.status(405).json({ message: `Only ${allowedHttpMethod} Method allowed` });
res.end();
}
};
};
export const postOnly = httpMethod("POST");
export const getOnly = httpMethod("GET");
export const patchOnly = httpMethod("PATCH");
export const deleteOnly = httpMethod("DELETE");
export const HTTP_POST = httpMethod("POST");
export const HTTP_GET = httpMethod("GET");
export const HTTP_PATCH = httpMethod("PATCH");
export const HTTP_DELETE = httpMethod("DELETE");