From ea7af68d998b0e32c5141239f150fb93c50afff9 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Thu, 27 Feb 2025 12:35:34 -0500 Subject: [PATCH] feat: add application kernel and middleware structure; implement console and exception handling kernels --- app/Console/Kernel.php | 27 +++++++++++++ app/Exceptions/Handler.php | 30 +++++++++++++++ app/Http/Kernel.php | 18 +++++++++ .../Middleware/RedirectIfAuthenticated.php | 28 ++++++++++++++ app/Http/Middleware/TrustHosts.php | 20 ++++++++++ app/Http/Middleware/ValidateSignature.php | 22 +++++++++++ app/Providers/RouteServiceProvider.php | 38 +++++++++++++++++++ 7 files changed, 183 insertions(+) create mode 100644 app/Console/Kernel.php create mode 100644 app/Exceptions/Handler.php create mode 100644 app/Http/Middleware/RedirectIfAuthenticated.php create mode 100644 app/Http/Middleware/TrustHosts.php create mode 100644 app/Http/Middleware/ValidateSignature.php create mode 100644 app/Providers/RouteServiceProvider.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php new file mode 100644 index 0000000..f04b3d0 --- /dev/null +++ b/app/Console/Kernel.php @@ -0,0 +1,27 @@ +command('inspire')->hourly(); + } + + /** + * Register the commands for the application. + */ + protected function commands(): void + { + $this->load(__DIR__.'/Commands'); + + require base_path('routes/console.php'); + } +} \ No newline at end of file diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php new file mode 100644 index 0000000..1489d5b --- /dev/null +++ b/app/Exceptions/Handler.php @@ -0,0 +1,30 @@ + + */ + protected $dontFlash = [ + 'current_password', + 'password', + 'password_confirmation', + ]; + + /** + * Register the exception handling callbacks for the application. + */ + public function register(): void + { + $this->reportable(function (Throwable $e) { + // + }); + } +} \ No newline at end of file diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 8bd78db..c309e4e 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -6,7 +6,13 @@ use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel { + /** + * The application's global HTTP middleware stack. + * + * @var array + */ protected $middleware = [ + // \App\Http\Middleware\TrustHosts::class, \App\Http\Middleware\TrustProxies::class, \Illuminate\Http\Middleware\HandleCors::class, \App\Http\Middleware\PreventRequestsDuringMaintenance::class, @@ -15,6 +21,11 @@ class Kernel extends HttpKernel \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, ]; + /** + * The application's route middleware groups. + * + * @var array> + */ protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, @@ -31,6 +42,13 @@ class Kernel extends HttpKernel ], ]; + /** + * The application's middleware aliases. + * + * Aliases may be used instead of class names to conveniently assign middleware to routes and groups. + * + * @var array + */ protected $middlewareAliases = [ 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php new file mode 100644 index 0000000..e7fb596 --- /dev/null +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -0,0 +1,28 @@ +check()) { + return redirect(RouteServiceProvider::HOME); + } + } + + return $next($request); + } +} \ No newline at end of file diff --git a/app/Http/Middleware/TrustHosts.php b/app/Http/Middleware/TrustHosts.php new file mode 100644 index 0000000..0ca0ed5 --- /dev/null +++ b/app/Http/Middleware/TrustHosts.php @@ -0,0 +1,20 @@ + + */ + public function hosts(): array + { + return [ + $this->allSubdomainsOfApplicationUrl(), + ]; + } +} \ No newline at end of file diff --git a/app/Http/Middleware/ValidateSignature.php b/app/Http/Middleware/ValidateSignature.php new file mode 100644 index 0000000..0490088 --- /dev/null +++ b/app/Http/Middleware/ValidateSignature.php @@ -0,0 +1,22 @@ + + */ + protected $except = [ + // 'fbclid', + // 'utm_campaign', + // 'utm_content', + // 'utm_medium', + // 'utm_source', + // 'utm_term', + ]; +} \ No newline at end of file diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..7578772 --- /dev/null +++ b/app/Providers/RouteServiceProvider.php @@ -0,0 +1,38 @@ +by($request->user()?->id ?: $request->ip()); + }); + + $this->routes(function () { + Route::middleware('api') + ->prefix('api') + ->group(base_path('routes/api.php')); + + Route::middleware('web') + ->group(base_path('routes/web.php')); + }); + } +} \ No newline at end of file