public/index.php line 4

  1. <?php
  2. use App\Kernel;
  3. require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
  4. $method $_SERVER['REQUEST_METHOD'];
  5. $allowedOrigins = [
  6.     'https://kindaka-frontend.vercel.app',
  7.     'http://localhost:3030/'// Add more origins here
  8. ];
  9. if ($method === 'OPTIONS') {
  10.     // $origin = $_SERVER['HTTP_ORIGIN'];
  11.     // if (in_array($origin, $allowedOrigins)) {
  12.         header("Access-Control-Allow-Origin: *");
  13.         header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE');
  14.         header('Access-Control-Allow-Headers: X-API-KEY,locale,lang, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization');
  15.         header('Access-Control-Allow-Credentials: true');
  16.         header('Access-Control-Max-Age: 86400'); // Cache the preflight response for 24 hours (optional)
  17.         http_response_code(204); // Set HTTP status code 204 (No Content) for the preflight response
  18.     // }
  19.     exit;
  20. }
  21. // $origin = $_SERVER['HTTP_ORIGIN'];
  22. // if (in_array($origin, $allowedOrigins)) {
  23.     header("Access-Control-Allow-Origin: *");
  24.     header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE');
  25.     header('Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization');
  26.     header('Access-Control-Allow-Credentials: true');
  27. // }
  28. return function (array $context) {
  29.     return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
  30. };