fix: Reorder CORS middleware to execute after RoutingMiddleware (LIFO)

This commit is contained in:
mwpn
2025-12-17 14:21:15 +07:00
parent 37098f4518
commit a8bd195743

View File

@@ -23,6 +23,10 @@ class AppBootstrap
{ {
$app = AppFactory::create(); $app = AppFactory::create();
// Add CORS middleware FIRST (will execute AFTER routing due to LIFO)
// This ensures CORS headers are added to all responses, including OPTIONS preflight
$app->add(new CorsMiddleware());
// Add body parsing middleware // Add body parsing middleware
$app->addBodyParsingMiddleware(); $app->addBodyParsingMiddleware();
@@ -56,10 +60,6 @@ class AppBootstrap
}); });
}); });
// Add CORS middleware LAST (after error middleware)
// This ensures CORS headers are added to all responses, including errors
$app->add(new CorsMiddleware());
return $app; return $app;
} }
} }