From d6ead5ae17bd9dec98661bdd9987a246261df985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Lain=C3=A9?= <2082554+phenixdotnet@users.noreply.github.com> Date: Tue, 26 Jan 2021 21:10:54 +0100 Subject: [PATCH] Added #8931: add health controller without session (#8978) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added health controller * Trying to move session middleware to web and api group to have health controller without session * Fix health route store the session Co-authored-by: Vincent Lainé --- app/Http/Controllers/HealthController.php | 23 ++++++++++++++++++ app/Http/Kernel.php | 1 + app/Http/Middleware/CheckForSetup.php | 2 +- app/Http/Middleware/NoSessionStore.php | 29 +++++++++++++++++++++++ app/Http/Middleware/VerifyCsrfToken.php | 1 + routes/web.php | 3 +-- 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/HealthController.php create mode 100644 app/Http/Middleware/NoSessionStore.php diff --git a/app/Http/Controllers/HealthController.php b/app/Http/Controllers/HealthController.php new file mode 100644 index 0000000000..5fc2c70f4e --- /dev/null +++ b/app/Http/Controllers/HealthController.php @@ -0,0 +1,23 @@ +json([ + "status" => "ok" + ]); + } +} \ No newline at end of file diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index dd29a4f66a..bedb8bcca5 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -14,6 +14,7 @@ class Kernel extends HttpKernel * @var array */ protected $middleware = [ + \App\Http\Middleware\NoSessionStore::class, \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, diff --git a/app/Http/Middleware/CheckForSetup.php b/app/Http/Middleware/CheckForSetup.php index 4cf7e72424..aa21f649fa 100644 --- a/app/Http/Middleware/CheckForSetup.php +++ b/app/Http/Middleware/CheckForSetup.php @@ -27,7 +27,7 @@ class CheckForSetup } } else { - if (!($request->is('setup*')) && !($request->is('.env'))) { + if (!($request->is('setup*')) && !($request->is('.env')) && !($request->is('health'))) { return redirect(url('/').'/setup'); } diff --git a/app/Http/Middleware/NoSessionStore.php b/app/Http/Middleware/NoSessionStore.php new file mode 100644 index 0000000000..86706a0974 --- /dev/null +++ b/app/Http/Middleware/NoSessionStore.php @@ -0,0 +1,29 @@ +except as $except) { + if ($request->is($except)) { + config()->set('session.driver', 'array'); + } + } + return $next($request); + } +} \ No newline at end of file diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 0faba9ee9b..f09e2ac9bd 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -12,5 +12,6 @@ class VerifyCsrfToken extends BaseVerifier * @var array */ protected $except = [ + 'health' ]; } diff --git a/routes/web.php b/routes/web.php index c4b64ad69e..8ef8438582 100644 --- a/routes/web.php +++ b/routes/web.php @@ -464,5 +464,4 @@ Route::group(['middleware' => 'web'], function () { Auth::routes(); - - +Route::get('/health', [ 'as' => 'health', 'uses' => 'HealthController@get']); \ No newline at end of file