Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: Try dynamic CORS in next.config

Richie McIlroy5ed790d58398
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index 44ee24426..041ca9fdb 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -44,37 +44,28 @@ const nextConfig = {
return [
{
source: "/api/playlist/(.*)",
- headers: [
- {
- key: "Access-Control-Allow-Origin",
- value: "https://cap.so",
- },
- {
- key: "Access-Control-Allow-Methods",
- value: "GET, POST, PUT, DELETE, OPTIONS",
- },
- {
- key: "Access-Control-Allow-Credentials",
- value: "true",
- },
- ],
- },
- {
- source: "/api/playlist/(.*)",
- headers: [
- {
- key: "Access-Control-Allow-Origin",
- value: "https://cap.link",
- },
- {
- key: "Access-Control-Allow-Methods",
- value: "GET, POST, PUT, DELETE, OPTIONS",
- },
- {
- key: "Access-Control-Allow-Credentials",
- value: "true",
- },
- ],
+ headers: async (req) => {
+ const allowedOrigins = ["https://cap.so", "https://cap.link"];
+ const origin = req.headers.origin;
+ if (allowedOrigins.includes(origin)) {
+ return [
+ {
+ key: "Access-Control-Allow-Origin",
+ value: origin,
+ },
+ {
+ key: "Access-Control-Allow-Methods",
+ value: "GET, POST, PUT, DELETE, OPTIONS",
+ },
+ {
+ key: "Access-Control-Allow-Credentials",
+ value: "true",
+ },
+ ];
+ } else {
+ return [];
+ }
+ },
},
{
source: "/api/desktop/(.*)",