diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 0f519526..9b8f7843 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -25,13 +25,12 @@ class Kernel extends HttpKernel protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, - \App\Http\Middleware\RemoveSlashMiddleware::class, + \App\Http\Middleware\RedirectIfUrlEndsWithSlash::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\Internationalization::class, \App\Http\Middleware\SaveOptionRepository::class, - //\App\Http\Middleware\VerifyCsrfToken::class, ], 'static' => [ @@ -49,7 +48,7 @@ class Kernel extends HttpKernel protected $routeMiddleware = [ 'auth' => \App\Http\Middleware\CheckAuthenticated::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, - 'admin' => \App\Http\Middleware\CheckAdminMiddleware::class, - 'player' => \App\Http\Middleware\CheckPlayerExistMiddleware::class + 'admin' => \App\Http\Middleware\CheckAdministrator::class, + 'player' => \App\Http\Middleware\CheckPlayerExist::class ]; } diff --git a/app/Http/Middleware/CheckAdminMiddleware.php b/app/Http/Middleware/CheckAdministrator.php similarity index 94% rename from app/Http/Middleware/CheckAdminMiddleware.php rename to app/Http/Middleware/CheckAdministrator.php index 59fbc6f7..13175d44 100644 --- a/app/Http/Middleware/CheckAdminMiddleware.php +++ b/app/Http/Middleware/CheckAdministrator.php @@ -2,7 +2,7 @@ namespace App\Http\Middleware; -class CheckAdminMiddleware +class CheckAdministrator { public function handle($request, \Closure $next) { diff --git a/app/Http/Middleware/CheckPlayerExistMiddleware.php b/app/Http/Middleware/CheckPlayerExist.php similarity index 92% rename from app/Http/Middleware/CheckPlayerExistMiddleware.php rename to app/Http/Middleware/CheckPlayerExist.php index fb86c5fa..f098d3bc 100644 --- a/app/Http/Middleware/CheckPlayerExistMiddleware.php +++ b/app/Http/Middleware/CheckPlayerExist.php @@ -6,7 +6,7 @@ use Event; use App\Models\Player; use App\Events\CheckPlayerExists; -class CheckPlayerExistMiddleware +class CheckPlayerExist { public function handle($request, \Closure $next) { @@ -27,7 +27,7 @@ class CheckPlayerExistMiddleware if (!Player::where('player_name', $player_name)->get()->isEmpty()) return $next($request); - if (option('return_200_when_notfound') == "1") { + if (option('return_200_when_notfound')) { return json([ 'player_name' => $player_name, 'errno' => 404, diff --git a/app/Http/Middleware/RedirectIfUrlEndsWithSlash.php b/app/Http/Middleware/RedirectIfUrlEndsWithSlash.php new file mode 100644 index 00000000..e9156679 --- /dev/null +++ b/app/Http/Middleware/RedirectIfUrlEndsWithSlash.php @@ -0,0 +1,24 @@ +getRequestUri(), -1) == '/') { + $baseUrl = $request->getBaseUrl(); + + // try to remove slash at the end of current url + $newUrl = substr($request->getRequestUri(), 0, -1); + + if ($newUrl != $baseUrl) { + return redirect(Str::replaceLast($baseUrl, '', $newUrl)); + } + } + + return $next($request); + } +} diff --git a/app/Http/Middleware/RemoveSlashMiddleware.php b/app/Http/Middleware/RemoveSlashMiddleware.php deleted file mode 100644 index 321a642c..00000000 --- a/app/Http/Middleware/RemoveSlashMiddleware.php +++ /dev/null @@ -1,23 +0,0 @@ -getRequestUri(), -1) == "/") { - $base_dir = $request->getBaseUrl(); - // try to remove slash at the end of current url - $new_url = substr($request->getRequestUri(), 0, -1); - - if ($new_url != $base_dir) { - return redirect(Str::replaceLast($base_dir, '', $new_url)); - } - } - - return $next($request); - } -}