Skip to content

Commit

Permalink
Support disabling of SPA prototype by using .env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Nov 18, 2023
1 parent bf86be3 commit 6e3b27f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Kernel extends HttpKernel
'api' => [
'throttle:60,1',
'bindings',
\App\Http\Middleware\CheckIfSpaPrototypeIsEnabled::class,
],
];

Expand Down
19 changes: 19 additions & 0 deletions app/Http/Middleware/CheckIfSpaPrototypeIsEnabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class CheckIfSpaPrototypeIsEnabled
{
public function handle(Request $request, Closure $next): Response
{
if (!config('app.spa_prototype_enabled')) {
abort(404);
}

return $next($request);
}
}
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,6 @@
*/

'disable_registration' => env('DISABLE_REGISTRATION', false),

'spa_prototype_enabled' => env('SPA_PROTOTYPE_ENABLED', true),
];
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use App\Http\Controllers\TransactionController;
use App\Http\Controllers\TranslationsController;
use App\Http\Controllers\VerifyController;
use App\Http\Middleware\CheckIfSpaPrototypeIsEnabled;
use Illuminate\Support\Facades\Route;

Route::get('/', [IndexController::class, 'index'])->name('index');
Expand Down Expand Up @@ -133,6 +134,7 @@
Route::get('/logout', [LogoutController::class, 'index'])->name('logout');

Route::prefix('prototype')
->middleware(CheckIfSpaPrototypeIsEnabled::class)
->group(function () {
Route::get('/', fn () => 'Hello world');
Route::get('/{any}', \App\Http\Controllers\PrototypeController::class)->where('any', '.*');
Expand Down

0 comments on commit 6e3b27f

Please sign in to comment.