mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-06-15 13:32:43 +01:00
Added healthcheck endpoints; Fixed filament check
This commit is contained in:
60
app/Http/Controllers/Web/HealthCheckController.php
Normal file
60
app/Http/Controllers/Web/HealthCheckController.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Web;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\User;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class HealthCheckController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Check if the application is up and running
|
||||||
|
* This check does not check the database or cache connectivity
|
||||||
|
*/
|
||||||
|
public function up(): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use App\Enums\Weekday;
|
use App\Enums\Weekday;
|
||||||
use Database\Factories\UserFactory;
|
use Database\Factories\UserFactory;
|
||||||
|
use Filament\Models\Contracts\FilamentUser;
|
||||||
use Filament\Panel;
|
use Filament\Panel;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
@@ -37,7 +38,7 @@ use Laravel\Passport\HasApiTokens;
|
|||||||
* @method static Builder<User> query()
|
* @method static Builder<User> query()
|
||||||
* @method Builder<User> belongsToOrganization(Organization $organization)
|
* @method Builder<User> belongsToOrganization(Organization $organization)
|
||||||
*/
|
*/
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable implements FilamentUser
|
||||||
{
|
{
|
||||||
use HasApiTokens;
|
use HasApiTokens;
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
@@ -104,7 +105,7 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public function canAccessPanel(Panel $panel): bool
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use App\Http\Controllers\Web\DashboardController;
|
use App\Http\Controllers\Web\DashboardController;
|
||||||
|
use App\Http\Controllers\Web\HealthCheckController;
|
||||||
use App\Http\Controllers\Web\HomeController;
|
use App\Http\Controllers\Web\HomeController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
@@ -59,3 +60,6 @@ Route::middleware([
|
|||||||
})->name('tags');
|
})->name('tags');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::get('health-check/up', [HealthCheckController::class, 'up']);
|
||||||
|
Route::get('health-check/debug', [HealthCheckController::class, 'debug']);
|
||||||
|
|||||||
Reference in New Issue
Block a user