diff --git a/app/Http/Controllers/Web/HealthCheckController.php b/app/Http/Controllers/Web/HealthCheckController.php new file mode 100644 index 00000000..3b4c38c2 --- /dev/null +++ b/app/Http/Controllers/Web/HealthCheckController.php @@ -0,0 +1,60 @@ +json([ + 'success' => true, + ]); + } + + /** + * Debug information for the application + * This check checks the database and cache connectivity + */ + public function debug(Request $request): JsonResponse + { + // Check database connectivity + User::query()->count(); + + // Check cache connectivity + Cache::put('health-check', Carbon::now()->timestamp); + + // Check ip address correct behind load balancer + $ipAddress = $request->ip(); + $hostname = $request->getHost(); + $secure = $request->secure(); + $isTrustedProxy = $request->isFromTrustedProxy(); + + $dbTimezone = DB::select('show timezone;'); + + return response() + ->json([ + 'ip_address' => $ipAddress, + 'hostname' => $hostname, + 'timestamp' => Carbon::now()->timestamp, + 'date_time_utc' => Carbon::now('UTC')->toDateTimeString(), + 'date_time_app' => Carbon::now()->toDateTimeString(), + 'timezone' => $dbTimezone[0]->TimeZone, + 'secure' => $secure, + 'is_trusted_proxy' => $isTrustedProxy, + ]); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 96cdbc13..0ebb13a9 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ use App\Enums\Weekday; use Database\Factories\UserFactory; +use Filament\Models\Contracts\FilamentUser; use Filament\Panel; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; @@ -37,7 +38,7 @@ * @method static Builder query() * @method Builder belongsToOrganization(Organization $organization) */ -class User extends Authenticatable +class User extends Authenticatable implements FilamentUser { use HasApiTokens; use HasFactory; @@ -104,7 +105,7 @@ class User extends Authenticatable public function canAccessPanel(Panel $panel): bool { - return in_array($this->email, config('auth.super_admins', []), true); + return in_array($this->email, config('auth.super_admins', []), true) && $this->hasVerifiedEmail(); } /** diff --git a/routes/web.php b/routes/web.php index 2ec71469..5f832e64 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ declare(strict_types=1); use App\Http\Controllers\Web\DashboardController; +use App\Http\Controllers\Web\HealthCheckController; use App\Http\Controllers\Web\HomeController; use Illuminate\Support\Facades\Route; use Inertia\Inertia; @@ -59,3 +60,6 @@ })->name('tags'); }); + +Route::get('health-check/up', [HealthCheckController::class, 'up']); +Route::get('health-check/debug', [HealthCheckController::class, 'debug']);