diff --git a/next.config.js b/next.config.js index 2dc79b35b2..ba2dcbf89b 100644 --- a/next.config.js +++ b/next.config.js @@ -11,6 +11,32 @@ module.exports = withAxiom({ "@calcom/prisma", "@calcom/trpc", ], + async headers() { + return [ + { + source: "/docs", + headers: [ + { + key: "Access-Control-Allow-Credentials", + value: "true", + }, + { + key: "Access-Control-Allow-Origin", + value: "*", + }, + { + key: "Access-Control-Allow-Methods", + value: "GET, OPTIONS, PATCH, DELETE, POST, PUT", + }, + { + key: "Access-Control-Allow-Headers", + value: + "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Content-Type, api_key, Authorization", + }, + ], + }, + ]; + }, async rewrites() { return { afterFiles: [ diff --git a/package.json b/package.json index 9ec3b44b5a..fea62daa18 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,10 @@ "@sentry/nextjs": "^7.20.0", "bcryptjs": "^2.4.3", "memory-cache": "^0.2.0", - "modify-response-middleware": "^1.1.0", "next": "~13.2.1", "next-api-middleware": "^1.0.1", "next-axiom": "^0.16.0", - "next-swagger-doc": "^0.3.4", + "next-swagger-doc": "^0.3.6", "next-validations": "^0.2.0", "typescript": "^4.9.4", "tzdata": "^1.0.30", diff --git a/pages/api/docs.ts b/pages/api/docs.ts index fb48027c35..1773d87457 100644 --- a/pages/api/docs.ts +++ b/pages/api/docs.ts @@ -1,6 +1,3 @@ -import modifyRes from "modify-response-middleware"; -import type { NextApiRequest, NextApiResponse } from "next"; -import { use } from "next-api-middleware"; import { withSwagger } from "next-swagger-doc"; import pjson from "~/package.json"; @@ -129,22 +126,4 @@ const swaggerHandler = withSwagger({ apiFolder: "pages/api", }); -export default use( - modifyRes((content: string, _req: NextApiRequest, res: NextApiResponse) => { - // Add all headers here instead of next.config.js as it is throwing error( Cannot set headers after they are sent to the client) for OPTIONS method - // It is known to happen only in Dev Mode. - res.setHeader("Access-Control-Allow-Credentials", "true"); - res.setHeader("Access-Control-Allow-Origin", "*"); - res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS, PATCH, DELETE, POST, PUT"); - res.setHeader( - "Access-Control-Allow-Headers", - "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Content-Type, api_key, Authorization" - ); - if (content) { - const parsed = JSON.parse(content); - // HACK: This is a hack to fix the swagger-ui issue with the extra channels property. - delete parsed.channels; - return Buffer.from(JSON.stringify(parsed)); - } - }) -)(swaggerHandler()); +export default swaggerHandler(); diff --git a/types.d.ts b/types.d.ts deleted file mode 100644 index 9a7af651d1..0000000000 --- a/types.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module "modify-response-middleware";