From a8bd1957435e6b36efc43d195bcc8a5bc5b7a935 Mon Sep 17 00:00:00 2001 From: mwpn Date: Wed, 17 Dec 2025 14:21:15 +0700 Subject: [PATCH] fix: Reorder CORS middleware to execute after RoutingMiddleware (LIFO) --- src/Bootstrap/app.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bootstrap/app.php b/src/Bootstrap/app.php index 4e55a97..d521724 100644 --- a/src/Bootstrap/app.php +++ b/src/Bootstrap/app.php @@ -23,6 +23,10 @@ class AppBootstrap { $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 $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; } }