Implemented redirection for SPA

This commit is contained in:
Kevin Frantz 2019-01-06 02:24:35 +01:00
parent 022cac0dc1
commit 77cd11233d
2 changed files with 27 additions and 5 deletions

View File

@ -3,7 +3,9 @@
namespace App\Controller; namespace App\Controller;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/** /**
* Offers an SPA with Vue.js. * Offers an SPA with Vue.js.
@ -12,12 +14,32 @@ use Symfony\Component\HttpFoundation\Request;
* @see https://de.wikipedia.org/wiki/Single-Page-Webanwendung * @see https://de.wikipedia.org/wiki/Single-Page-Webanwendung
* *
* @author kevinfrantz * @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));
} }
} }

View File

@ -16,7 +16,7 @@ class RoutesGetStatusIntegrationTest extends KernelTestCase
'register' => 301, 'register' => 301,
'logout' => 302, 'logout' => 302,
'profile/edit' => 302, 'profile/edit' => 302,
'spa' => 200, 'spa' => 302,
]; ];
public function setUp(): void public function setUp(): void