-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ReflectionsProjections/dev/aydan/cors
Allowing everything for cors
- Loading branch information
Showing
1 changed file
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |