title: domain.com has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status
body: <p>Handling preflight requests from React application to Symfony is getting too difficult now, I am trying to fix this for the last 8 hours, Here is the error that I am getting,</p>
  <p><code>Access to XMLHttpRequest at 'https://mylocaldomain.com/validate-token' from origin 'http://myreactapplocal:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.</code></p>
  <p>I tried adding the code from this post in <a href="https://stackoverflow.com/a/57915483/3664745">here</a> in public/index.php and it worked, I am trying to implement the same in the listener as I do not want to edit the public/index.php and it's not working via the listener, below is my listener code</p>
  <pre><code>
  
  namespace App\EventListener;
  
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  use Symfony\Component\DependencyInjection\ContainerInterface;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\HttpKernel\Event\RequestEvent;
  use Symfony\Component\HttpKernel\Event\ResponseEvent;
  use Symfony\Component\HttpKernel\HttpKernel;
  use Symfony\Component\HttpKernel\KernelEvents;
  
  class CorsListener implements EventSubscriberInterface
  {
  
  
      private $container;
  
      public function __construct(ContainerInterface $container)
      {
          $this-&gt;container = $container;
      }
  
      public static function getSubscribedEvents(): array
      {
          return [
              RequestEvent::class =&gt; 'onRequestEvent',
              ResponseEvent::class =&gt; 'onResponseEvent',
          ];
      }
  
  
      public function onRequestEvent(RequestEvent $event)
      {
          if (HttpKernel::MASTER_REQUEST != $event-&gt;getRequestType()) {
              return;
          }
  
          $request = $event-&gt;getRequest();
          $method  = $request-&gt;getRealMethod();
          if ('OPTIONS' === $method) {
              $response = new Response();
              $response-&gt;headers-&gt;set('Access-Control-Allow-Headers', 'X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization');
              $event-&gt;setResponse($response);
          }
      }
  
      public function onResponseEvent(ResponseEvent $event)
      {
          // Don't do anything if it's not the master request.
          if (!$event-&gt;isMasterRequest()) {
              return;
          }
          $response = $event-&gt;getResponse();
          $response-&gt;headers-&gt;set('Access-Control-Allow-Origin', '*');
          $response-&gt;headers-&gt;set('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE');
          $response-&gt;headers-&gt;set('Access-Control-Allow-Headers', 'Content-Type,Authorization');
      }
  }
  
  </code></pre>
  <p>Any kind of help/lead to resolving this issue is appreciated!!</p>