custom/plugins/MasterFFLCheckout/src/Subscriber/CorsResponseSubscriber.php line 18

Open in your IDE?
  1. <?php
  2. namespace MasterFFL\Checkout\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. class CorsResponseSubscriber implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents(): array
  9.     {
  10.         return [
  11.             KernelEvents::RESPONSE => 'onKernelResponse',
  12.         ];
  13.     }
  14.     public function onKernelResponse(ResponseEvent $event): void
  15.     {
  16.         $response $event->getResponse();
  17.         $request $event->getRequest();
  18.         // Only allow on /api/* (Admin API)
  19.         if (strpos($request->getPathInfo(), '/api/') !== 0) {
  20.             return;
  21.         }
  22.         // Replace this with your frontend domain
  23.         $allowedOrigin 'https://ffl360-qa.masterffl.com';
  24.         $origin $request->headers->get('Origin');
  25.         if ($origin === $allowedOrigin) {
  26.             $response->headers->set('Access-Control-Allow-Origin'$origin);
  27.             $response->headers->set('Access-Control-Allow-Headers''Content-Type, Authorization');
  28.             $response->headers->set('Access-Control-Allow-Methods''GET, POST, PUT, DELETE, OPTIONS');
  29.             $response->headers->set('Access-Control-Allow-Credentials''true');
  30.         }
  31.         // Optional: handle preflight
  32.         if ($request->getMethod() === 'OPTIONS') {
  33.             $response->setStatusCode(200);
  34.         }
  35.     }
  36. }