src/Application/Controller/App/FrontendController.php line 32

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2022 by Noma Solutions.
  4.  * This software is the proprietary information of Noma Solutions.
  5.  *
  6.  * All rights reserved
  7.  */
  8. namespace BackendApi\Application\Controller\App;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class FrontendController extends AbstractController
  15. {
  16.     private bool $frontendEnabled;
  17.     private string $projectPath;
  18.     public function __construct(bool $frontendEnabledstring $projectPath)
  19.     {
  20.         $this->frontendEnabled $frontendEnabled;
  21.         $this->projectPath $projectPath;
  22.     }
  23.     /**
  24.      * @Route("/", name="homepage")
  25.      */
  26.     public function index(): RedirectResponse
  27.     {
  28.         return $this->redirectToRoute('app_admin');
  29.     }
  30.     /**
  31.      * @Route("/front")
  32.      * @Route("/front/{moduleUrl}", name="angular_index", requirements={"moduleUrl": "^(?!(test|doc|api|_wdt|_profiler|admin|coreapi|oauth|webview|app\/doc\/|app\/doc$)).*"})
  33.      * @param Request $request
  34.      * @return Response
  35.      */
  36.     public function indexAction(Request $request): Response
  37.     {
  38.         if (!$this->frontendEnabled) {
  39.             throw $this->createNotFoundException();
  40.         }
  41.         $indexHtmlPath $this->projectPath DIRECTORY_SEPARATOR 'public' DIRECTORY_SEPARATOR 'index.html';
  42.         if (!file_exists($indexHtmlPath)) {
  43.             throw $this->createNotFoundException('No index.html file in public dir');
  44.         }
  45.         $contents file_get_contents($indexHtmlPath);
  46.         $contents str_replace([
  47.             'http://localhost:10010'
  48.         ], [
  49.             $request->getSchemeAndHttpHost()
  50.         ], $contents);
  51.         return new Response($contents);
  52.     }
  53. }