From 04052c53b459ab1d13cdbce589c7c913b0826b44 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 15 Apr 2022 18:12:25 +0200 Subject: [PATCH] cleanup no cors middleware --- lib/helpers/withCors.ts | 17 ----------------- lib/helpers/withCorsMiddleware.ts | 12 ------------ pages/api/docs.ts | 2 -- 3 files changed, 31 deletions(-) delete mode 100644 lib/helpers/withCors.ts delete mode 100644 lib/helpers/withCorsMiddleware.ts diff --git a/lib/helpers/withCors.ts b/lib/helpers/withCors.ts deleted file mode 100644 index e0034ae1dd..0000000000 --- a/lib/helpers/withCors.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { NextMiddleware } from "next-api-middleware"; -import NextCors from "nextjs-cors"; - -export const withCors: NextMiddleware = async (req, res, next) => { - // Run the cors middleware - // nextjs-cors uses the cors package, so we invite you to check the documentation https://github.com/expressjs/cors - await NextCors(req, res, { - // Options - methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"], - origin: "*", - optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204 - }); - - // Rest of the API logic - // Execute the remaining middleware - await next(); -}; diff --git a/lib/helpers/withCorsMiddleware.ts b/lib/helpers/withCorsMiddleware.ts deleted file mode 100644 index 14182eff99..0000000000 --- a/lib/helpers/withCorsMiddleware.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { label } from "next-api-middleware"; - -import { withCors } from "./withCors"; - -const withCorsMiddleware = label( - { - withCors, - }, - ["withCors"] // <-- Provide a list of middleware to call automatically -); - -export { withCorsMiddleware }; diff --git a/pages/api/docs.ts b/pages/api/docs.ts index 34ad0d7c5e..d9aa75d18c 100644 --- a/pages/api/docs.ts +++ b/pages/api/docs.ts @@ -2,8 +2,6 @@ import jsonSchema from "@/json-schema/json-schema.json"; import pjson from "@/package.json"; import { withSwagger } from "next-swagger-doc"; -import { withCorsMiddleware } from "@lib/helpers/withCorsMiddleware"; - const swaggerHandler = withSwagger({ definition: { openapi: "3.0.0",