src/EventSubscriber/CorsSubscriber.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Flex\Response;
  6. class CorsSubscriber implements EventSubscriberInterface
  7. {
  8.     public function onKernelRequest(RequestEvent $event)
  9.     {
  10.         if('OPTIONS' == $_SERVER['REQUEST_METHOD']){
  11.             header('Access-Control-Allow-Origin: *');
  12.             header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization, Auth");
  13.             header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
  14.             header("Allow: GET, POST, OPTIONS, PUT, DELETE");
  15.             die();
  16.         }
  17.     }
  18.     public static function getSubscribedEvents()
  19.     {
  20.         return [
  21.             'kernel.request' => 'onKernelRequest',
  22.         ];
  23.     }
  24. }