From 06ce614c2bbb0b5f001496eb35c76580f29e8377 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Mon, 22 Jul 2024 04:27:02 +0200 Subject: [PATCH] Routes for React --- exam/.htaccess | 4 ++-- exam/classes/Input/Input.php | 12 ++++++++---- exam/dist/.htaccess | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/exam/.htaccess b/exam/.htaccess index 5d415df..e4b6368 100644 --- a/exam/.htaccess +++ b/exam/.htaccess @@ -11,11 +11,11 @@ RewriteRule ^ api/index.php [L,NC,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !/api/docs RewriteCond %{REQUEST_FILENAME} !/dist -RewriteRule ^ dist [L,NC,QSA] +RewriteRule ^ dist/index.html [L,NC,QSA] ## Rewrite all files unless in the directories specified RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} !/storage/.* RewriteCond %{REQUEST_FILENAME} !/dist/.* RewriteCond %{REQUEST_FILENAME} !/api/docs -RewriteRule ^ dist [L,NC,QSA] \ No newline at end of file +RewriteRule ^ dist/index.html [L,NC,QSA] \ No newline at end of file diff --git a/exam/classes/Input/Input.php b/exam/classes/Input/Input.php index 80aaebf..7b4d5ad 100644 --- a/exam/classes/Input/Input.php +++ b/exam/classes/Input/Input.php @@ -8,21 +8,25 @@ class Input { public static function post(string $index, $defaultValue = null) { - return Request::request()->getInputHandler()->post($index, $defaultValue); + $value = Request::request()->getInputHandler()->post($index, $defaultValue); + return empty($value) ? null : $value->getValue(); } public static function patch(string $index, $defaultValue = null) { - return Request::request()->getInputHandler()->post($index, $defaultValue); + $value = Request::request()->getInputHandler()->post($index, $defaultValue); + return empty($value) ? null : $value->getValue(); } public static function get(string $index, $defaultValue = null) { - return Request::request()->getInputHandler()->get($index, $defaultValue); + $value = Request::request()->getInputHandler()->get($index, $defaultValue); + return empty($value) ? null : $value->getValue(); } public static function file(string $index, $defaultValue = null) { - return Request::request()->getInputHandler()->file($index, $defaultValue); + $value = Request::request()->getInputHandler()->file($index, $defaultValue); + return empty($value) ? null : $value->getValue(); } } diff --git a/exam/dist/.htaccess b/exam/dist/.htaccess index aadaa05..3deb052 100644 --- a/exam/dist/.htaccess +++ b/exam/dist/.htaccess @@ -1,7 +1,7 @@ RewriteEngine On -RewriteBase /phpCourse/exam/dist/ +RewriteBase /phpCourse/exam/dist -## Frontend routing required all non files to be rewritten to the entry point +## Disallow direct entry over the dist RewriteCond %{REQUEST_FILENAME} !-f -RewriteRule ^ index.html [L,NC,QSA] \ No newline at end of file +RewriteRule ^ / [L,NC,QSA,F] \ No newline at end of file