Skip to content

Commit

Permalink
Merge pull request #21 from ReflectionsProjections/dev/aydan/cors
Browse files Browse the repository at this point in the history
Allowing everything for cors
  • Loading branch information
AydanPirani authored Apr 14, 2024
2 parents d3c599b + 4cb44a0 commit ef04060
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/middleware/cors-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import cors from "cors";

// Allow CORS for Netlify deploy previews
const allowedOrigins = ["https://reflectionsprojections.org"];
// Function to check if the origin matches the deploy preview format
function isNetlifyDeployPreview(origin: string) {
const regex = new RegExp("deploy-preview-[0-9]*(--rp2024.netlify.app)(.*)");
return regex.test(origin);
}
// // Allow CORS for Netlify deploy previews
// const allowedOrigins = ["https://reflectionsprojections.org"];
// // Function to check if the origin matches the deploy preview format
// function isNetlifyDeployPreview(origin: string) {
// const regex = new RegExp("deploy-preview-[0-9]*(--rp2024.netlify.app)(.*)");
// return regex.test(origin);
// }
//
// const corsMiddleware = cors({
// origin: function (origin, callback) {
// if (
// !origin ||
// allowedOrigins.includes(origin) ||
// isNetlifyDeployPreview(origin)
// ) {
// callback(null, true);
// } else {
// callback(new Error("Not allowed by CORS"));
// }
// },
// });

const corsMiddleware = cors({
origin: function (origin, callback) {
if (
!origin ||
allowedOrigins.includes(origin) ||
isNetlifyDeployPreview(origin)
) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
});

export default corsMiddleware;
export default cors();

0 comments on commit ef04060

Please sign in to comment.