@@ -59,21 +59,33 @@ const defaultStocks = [
59
59
60
60
const app = express ( ) ;
61
61
62
- // Configure CORS
62
+ // Configure CORS with more permissive options for development
63
63
app . use ( cors ( {
64
64
origin : [
65
65
'https://portfolio-tracker-sage.vercel.app' ,
66
66
'https://portfolio-tracker-hackstyx.vercel.app' ,
67
- 'http://localhost:5173'
67
+ 'https://portfolio-tracker-kc46ea0ei-hackstyxs-projects.vercel.app' ,
68
+ 'http://localhost:5173' ,
69
+ / \. v e r c e l \. a p p $ / // Allow all Vercel preview deployments
68
70
] ,
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
71
75
} ) ) ;
72
76
77
+ // Pre-flight requests
78
+ app . options ( '*' , cors ( ) ) ;
79
+
73
80
app . use ( express . json ( ) ) ;
74
81
75
82
// Health check endpoint
76
83
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
+
77
89
res . json ( { status : 'ok' , message : 'Server is running' } ) ;
78
90
} ) ;
79
91
0 commit comments