From 77cd11233d7ce1ed44d6d93fb07f193a3fb11641 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 6 Jan 2019 02:24:35 +0100 Subject: [PATCH] Implemented redirection for SPA --- .../symfony/src/Controller/SPAController.php | 30 ++++++++++++++++--- .../RoutesGetStatusIntegrationTest.php | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/application/symfony/src/Controller/SPAController.php b/application/symfony/src/Controller/SPAController.php index f62a961..0efb40b 100644 --- a/application/symfony/src/Controller/SPAController.php +++ b/application/symfony/src/Controller/SPAController.php @@ -3,7 +3,9 @@ namespace App\Controller; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Annotation\Route; /** * Offers an SPA with Vue.js. @@ -12,12 +14,32 @@ use Symfony\Component\HttpFoundation\Request; * @see https://de.wikipedia.org/wiki/Single-Page-Webanwendung * * @author kevinfrantz - * - * @todo Write tests! */ -class SPAController extends AbstractController +final class SPAController extends AbstractController { - public function spa(Request $request): Response + /** + * @todo put this in an .env file + * + * @var int + */ + const SPA_PORT = 82; + + private function getSpaUrl(Request $request): string { + $url = str_replace('/spa/', '', $request->getUri()); + $url = str_replace('/spa', '', $url); + $url .= ':'.self::SPA_PORT; + + return $url; + } + + /** + * @Route("/spa",methods={"GET"}) + * + * @return Response + */ + public function spa(Request $request): RedirectResponse + { + return new RedirectResponse($this->getSpaUrl($request)); } } diff --git a/application/symfony/tests/Integration/Controller/RoutesGetStatusIntegrationTest.php b/application/symfony/tests/Integration/Controller/RoutesGetStatusIntegrationTest.php index 2eba8a4..029b218 100644 --- a/application/symfony/tests/Integration/Controller/RoutesGetStatusIntegrationTest.php +++ b/application/symfony/tests/Integration/Controller/RoutesGetStatusIntegrationTest.php @@ -16,7 +16,7 @@ class RoutesGetStatusIntegrationTest extends KernelTestCase 'register' => 301, 'logout' => 302, 'profile/edit' => 302, - 'spa' => 200, + 'spa' => 302, ]; public function setUp(): void