vendor/pentatrion/vite-bundle/src/Controller/ViteController.php line 32

Open in your IDE?
  1. <?php
  2. namespace Pentatrion\ViteBundle\Controller;
  3. use Exception;
  4. use Pentatrion\ViteBundle\Asset\EntrypointsLookup;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Contracts\HttpClient\HttpClientInterface;
  7. class ViteController
  8. {
  9.     public $httpClient;
  10.     public string $viteBase;
  11.     private $entrypointsLookup;
  12.     private $viteDevServer;
  13.     public function __construct(
  14.         string $viteBase,
  15.         HttpClientInterface $httpClient,
  16.         EntrypointsLookup $entrypointsLookup
  17.     ) {
  18.         $this->viteBase $viteBase;
  19.         $this->httpClient $httpClient;
  20.         $this->entrypointsLookup $entrypointsLookup;
  21.         $this->viteDevServer $this->entrypointsLookup->getViteServer();
  22.     }
  23.     public function proxyBuild($path): Response
  24.     {
  25.         if (is_null($this->viteDevServer) || false === $this->viteDevServer) {
  26.             return new Exception('Vite dev server not available');
  27.         }
  28.         $response $this->httpClient->request(
  29.             'GET',
  30.             $this->viteDevServer['origin'].$this->viteBase.$path
  31.         );
  32.         $content $response->getContent();
  33.         $statusCode $response->getStatusCode();
  34.         $headers $response->getHeaders();
  35.         return new Response($content$statusCode$headers);
  36.     }
  37. }