Merge pull request #36 from calcom/fix/cors

This commit is contained in:
Agusti Fernandez
2022-04-15 16:11:42 +02:00
committed by GitHub
3 changed files with 22 additions and 1 deletions
+17
View File
@@ -0,0 +1,17 @@
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();
};
+1
View File
@@ -38,6 +38,7 @@
"next-swagger-doc": "^0.2.1",
"next-transpile-modules": "^9.0.0",
"next-validations": "^0.1.11",
"nextjs-cors": "^2.1.1",
"typescript": "^4.6.3"
}
}
+4 -1
View File
@@ -2,6 +2,9 @@ import jsonSchema from "@/json-schema/json-schema.json";
import pjson from "@/package.json";
import { withSwagger } from "next-swagger-doc";
import { withCors } from "@lib/helpers/withCors";
import { withMiddleware } from "@lib/helpers/withMiddleware";
const swaggerHandler = withSwagger({
definition: {
openapi: "3.0.0",
@@ -16,4 +19,4 @@ const swaggerHandler = withSwagger({
tags: ["users", "teams", "memeberships"],
sort: true,
});
export default swaggerHandler();
export default withMiddleware(withCors)(swaggerHandler());