Skip to content

Commit 82f3f8e

Browse files
Datakult0rclaude
andcommitted
fix: Use CORS function with regex for Vercel preview deployments
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent d596ddc commit 82f3f8e

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

backend/src/server.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,27 @@ app.use(helmet());
3636

3737
// CORS Configuration for Production
3838
const corsOptions = {
39-
origin: [
40-
'http://localhost:5173', // Local development
41-
'https://ai-grant-crawler-a2a-pro.vercel.app', // Production frontend
42-
'https://ai-grant-crawler-a2a-pro-*.vercel.app' // Vercel preview deployments
43-
],
39+
origin: function (origin, callback) {
40+
const allowedOrigins = [
41+
'http://localhost:5173',
42+
'https://ai-grant-crawler-a2a-pro.vercel.app'
43+
];
44+
45+
// Allow requests with no origin (like mobile apps or curl requests)
46+
if (!origin) return callback(null, true);
47+
48+
// Check if origin is in allowed list
49+
if (allowedOrigins.includes(origin)) {
50+
return callback(null, true);
51+
}
52+
53+
// Allow all Vercel preview deployments
54+
if (origin.match(/^https:\/\/ai-grant-crawler-a2a-pro-.*\.vercel\.app$/)) {
55+
return callback(null, true);
56+
}
57+
58+
callback(new Error('Not allowed by CORS'));
59+
},
4460
credentials: true,
4561
optionsSuccessStatus: 200
4662
};

0 commit comments

Comments
 (0)