@@ -10,29 +10,29 @@ void CorsFilter::doFilter(const drogon::HttpRequestPtr& req,
10
10
drogon::FilterChainCallback&& fccb) {
11
11
API_LOG_DEBUG (" Processing CORS request for path: {}" , req->getPath ());
12
12
13
- // Create response for handling CORS
14
- auto resp = drogon::HttpResponse::newHttpResponse ();
15
-
16
- // Add CORS headers matching your config
17
- resp->addHeader (" Access-Control-Allow-Origin" , " http://localhost:3000" );
18
- resp->addHeader (" Access-Control-Allow-Methods" , " GET,POST,OPTIONS" );
19
- resp->addHeader (" Access-Control-Allow-Headers" , " Content-Type,Authorization" );
20
- resp->addHeader (" Access-Control-Max-Age" , " 86400" );
21
-
22
- // Handle preflight request
23
13
if (req->getMethodString () == " OPTIONS" ) {
14
+ // Handle preflight request
24
15
API_LOG_DEBUG (" Handling OPTIONS preflight request" );
25
- resp->setStatusCode (drogon::k204NoContent);
16
+ auto resp = drogon::HttpResponse::newHttpResponse ();
17
+
18
+ // Add CORS headers for preflight
19
+ resp->addHeader (" Access-Control-Allow-Origin" , " http://localhost:3000" );
20
+ resp->addHeader (" Access-Control-Allow-Methods" , " GET, POST, OPTIONS" );
21
+ resp->addHeader (" Access-Control-Allow-Headers" , " Content-Type" );
22
+ resp->addHeader (" Access-Control-Max-Age" , " 86400" );
23
+
24
+ // Important: Set status 200 for OPTIONS
25
+ resp->setStatusCode (drogon::k200OK);
26
26
fcb (resp);
27
27
return ;
28
28
}
29
29
30
- // For non-OPTIONS requests, add CORS headers to the response
31
- req-> addHeader ( " Access-Control-Allow-Origin " , " http://localhost:3000 " );
32
- req ->addHeader (" Access-Control-Allow-Methods " , " GET,POST,OPTIONS " );
33
- req ->addHeader (" Access-Control-Allow-Headers " , " Content-Type,Authorization " );
34
- req ->addHeader (" Access-Control-Max-Age " , " 86400 " );
35
-
30
+ // For non-OPTIONS requests
31
+ auto resp = drogon::HttpResponse::newHttpResponse ( );
32
+ resp ->addHeader (" Access-Control-Allow-Origin " , " http://localhost:3000 " );
33
+ resp ->addHeader (" Access-Control-Allow-Methods " , " GET, POST, OPTIONS " );
34
+ resp ->addHeader (" Access-Control-Allow-Headers " , " Content-Type " );
35
+
36
36
// Continue with the request chain
37
37
fccb ();
38
38
}
0 commit comments