Skip to content

Commit 5251d93

Browse files
committed
Update CORS configuration to allow Vercel preview domains
1 parent dfd66bf commit 5251d93

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

backend/src/server.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,33 @@ const defaultStocks = [
5959

6060
const app = express();
6161

62-
// Configure CORS
62+
// Configure CORS with more permissive options for development
6363
app.use(cors({
6464
origin: [
6565
'https://portfolio-tracker-sage.vercel.app',
6666
'https://portfolio-tracker-hackstyx.vercel.app',
67-
'http://localhost:5173'
67+
'https://portfolio-tracker-kc46ea0ei-hackstyxs-projects.vercel.app',
68+
'http://localhost:5173',
69+
/\.vercel\.app$/ // Allow all Vercel preview deployments
6870
],
69-
methods: ['GET', 'POST', 'PUT', 'DELETE'],
70-
allowedHeaders: ['Content-Type', 'Authorization']
71+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
72+
allowedHeaders: ['Content-Type', 'Authorization'],
73+
credentials: true,
74+
optionsSuccessStatus: 200
7175
}));
7276

77+
// Pre-flight requests
78+
app.options('*', cors());
79+
7380
app.use(express.json());
7481

7582
// Health check endpoint
7683
app.get('/api/health', (req, res) => {
84+
// Add CORS headers explicitly for the health endpoint
85+
res.header('Access-Control-Allow-Origin', '*');
86+
res.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
87+
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
88+
7789
res.json({ status: 'ok', message: 'Server is running' });
7890
});
7991

0 commit comments

Comments
 (0)