Skip to content

Commit

Permalink
Extended healthcheck debug in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Nov 15, 2024
1 parent 2cf9b3a commit 9e77500
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
40 changes: 28 additions & 12 deletions app/Http/Controllers/Web/HealthCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,34 @@ public function debug(Request $request): JsonResponse

$dbTimezone = DB::select('show timezone;');

$response = [
'ip_address' => $ipAddress,
'url' => $request->url(),
'path' => $request->path(),
'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,
];

if (app()->hasDebugModeEnabled()) {
$response['app_debug'] = true;
$response['app_url'] = config('app.url');
$response['app_env'] = app()->environment();
$response['app_timezone'] = config('app.timezone');
$response['app_force_https'] = config('app.force_https');
$response['trusted_proxies'] = config('trustedproxy.proxies');
$headers = $request->headers->all();
if (isset($headers['cookie'])) {
$headers['cookie'] = '***';
}
$response['headers'] = $headers;
}

return response()
->json([
'ip_address' => $ipAddress,
'url' => $request->url(),
'path' => $request->path(),
'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,
]);
->json($response);
}
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

'asset_url' => env('ASSET_URL'),

'force_https' => env('APP_FORCE_HTTPS', false),
'force_https' => (bool) env('APP_FORCE_HTTPS', false),

/*
|--------------------------------------------------------------------------
Expand Down
47 changes: 42 additions & 5 deletions tests/Unit/Endpoint/Web/HealthCheckEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,57 @@ public function test_up_endpoint_returns_ok(): void

public function test_debug_endpoint_returns_ok(): void
{
// Arrange
config(['app.debug' => false]);

// Act
$response = $this->get('health-check/debug');

// Assert
$response->assertSuccessful();
$response->assertJsonStructure([
'ip_address',
$response->assertExactJsonStructure([
'date_time_app',
'date_time_utc',
'hostname',
'ip_address',
'is_trusted_proxy',
'path',
'secure',
'timestamp',
'date_time_utc',
'date_time_app',
'timezone',
'secure',
'url',
]);
config(['app.debug' => true]);
}

public function test_debug_endpoint_returns_more_information_if_debug_mode_is_enabled(): void
{
// Arrange
config(['app.debug' => true]);

// Act
$response = $this->get('health-check/debug');

// Assert
$response->assertSuccessful();
$response->assertExactJsonStructure([
'app_debug',
'app_env',
'app_force_https',
'app_timezone',
'app_url',
'date_time_app',
'date_time_utc',
'headers',
'hostname',
'ip_address',
'is_trusted_proxy',
'path',
'secure',
'timestamp',
'timezone',
'trusted_proxies',
'url',
]);
}
}

0 comments on commit 9e77500

Please sign in to comment.