public/index.php line 28

Open in your IDE?
  1. <?php
  2. // Liste des origines autorisées
  3. $allowedOrigins = [
  4.     'http://localhost:4200'// Développement local
  5.     'https://competitions.lrsdev.fr' // Production
  6. ];
  7. // Récupérer l'origine de la requête
  8. $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
  9. // Vérifier si l'origine est autorisée
  10. if (in_array($origin$allowedOrigins)) {
  11.     header("Access-Control-Allow-Origin: $origin"); // Autoriser cette origine
  12.     header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE"); // Méthodes HTTP autorisées
  13.     header("Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization"); // En-têtes autorisés
  14.     header("Access-Control-Allow-Credentials: true"); // Autoriser les cookies/sessions
  15. }
  16. // Gérer les requêtes prévol (OPTIONS)
  17. if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
  18.     http_response_code(200); // Réponse OK pour OPTIONS
  19.     exit(); // Terminer l'exécution ici pour OPTIONS
  20. }
  21. use App\Kernel;
  22. require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
  23. return function (array $context) {
  24.     return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
  25. };