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