fix: Register CORS middleware di public/index.php sebelum semua route

This commit is contained in:
mwpn
2025-12-17 14:29:43 +07:00
parent a87d29c228
commit dae5e9d2d5

View File

@@ -6,6 +6,7 @@ require __DIR__ . '/../vendor/autoload.php';
use App\Bootstrap\AppBootstrap;
use App\Config\AppConfig;
use App\Middleware\CorsMiddleware;
use App\Modules\Auth\AuthRoutes;
use App\Modules\Health\HealthRoutes;
use App\Modules\Retribusi\Dashboard\DashboardRoutes;
@@ -19,6 +20,9 @@ AppConfig::loadEnv(__DIR__ . '/..');
// Bootstrap application
$app = AppBootstrap::create();
// ✅ REGISTER CORS MIDDLEWARE GLOBAL (PALING ATAS)
$app->add(new CorsMiddleware());
// Global OPTIONS route for CORS preflight (must be before other routes)
$app->options('/{routes:.+}', function ($request, $response) {
return $response->withStatus(204);