Skip to content

Commit 9e77500

Browse files
committed
Extended healthcheck debug in debug mode
1 parent 2cf9b3a commit 9e77500

File tree

3 files changed

+71
-18
lines changed

3 files changed

+71
-18
lines changed

app/Http/Controllers/Web/HealthCheckController.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,34 @@ public function debug(Request $request): JsonResponse
4545

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

48+
$response = [
49+
'ip_address' => $ipAddress,
50+
'url' => $request->url(),
51+
'path' => $request->path(),
52+
'hostname' => $hostname,
53+
'timestamp' => Carbon::now()->timestamp,
54+
'date_time_utc' => Carbon::now('UTC')->toDateTimeString(),
55+
'date_time_app' => Carbon::now()->toDateTimeString(),
56+
'timezone' => $dbTimezone[0]->TimeZone,
57+
'secure' => $secure,
58+
'is_trusted_proxy' => $isTrustedProxy,
59+
];
60+
61+
if (app()->hasDebugModeEnabled()) {
62+
$response['app_debug'] = true;
63+
$response['app_url'] = config('app.url');
64+
$response['app_env'] = app()->environment();
65+
$response['app_timezone'] = config('app.timezone');
66+
$response['app_force_https'] = config('app.force_https');
67+
$response['trusted_proxies'] = config('trustedproxy.proxies');
68+
$headers = $request->headers->all();
69+
if (isset($headers['cookie'])) {
70+
$headers['cookie'] = '***';
71+
}
72+
$response['headers'] = $headers;
73+
}
74+
4875
return response()
49-
->json([
50-
'ip_address' => $ipAddress,
51-
'url' => $request->url(),
52-
'path' => $request->path(),
53-
'hostname' => $hostname,
54-
'timestamp' => Carbon::now()->timestamp,
55-
'date_time_utc' => Carbon::now('UTC')->toDateTimeString(),
56-
'date_time_app' => Carbon::now()->toDateTimeString(),
57-
'timezone' => $dbTimezone[0]->TimeZone,
58-
'secure' => $secure,
59-
'is_trusted_proxy' => $isTrustedProxy,
60-
]);
76+
->json($response);
6177
}
6278
}

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

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

68-
'force_https' => env('APP_FORCE_HTTPS', false),
68+
'force_https' => (bool) env('APP_FORCE_HTTPS', false),
6969

7070
/*
7171
|--------------------------------------------------------------------------

tests/Unit/Endpoint/Web/HealthCheckEndpointTest.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,57 @@ public function test_up_endpoint_returns_ok(): void
3333

3434
public function test_debug_endpoint_returns_ok(): void
3535
{
36+
// Arrange
37+
config(['app.debug' => false]);
38+
3639
// Act
3740
$response = $this->get('health-check/debug');
3841

3942
// Assert
4043
$response->assertSuccessful();
41-
$response->assertJsonStructure([
42-
'ip_address',
44+
$response->assertExactJsonStructure([
45+
'date_time_app',
46+
'date_time_utc',
4347
'hostname',
48+
'ip_address',
49+
'is_trusted_proxy',
50+
'path',
51+
'secure',
4452
'timestamp',
45-
'date_time_utc',
46-
'date_time_app',
4753
'timezone',
48-
'secure',
54+
'url',
55+
]);
56+
config(['app.debug' => true]);
57+
}
58+
59+
public function test_debug_endpoint_returns_more_information_if_debug_mode_is_enabled(): void
60+
{
61+
// Arrange
62+
config(['app.debug' => true]);
63+
64+
// Act
65+
$response = $this->get('health-check/debug');
66+
67+
// Assert
68+
$response->assertSuccessful();
69+
$response->assertExactJsonStructure([
70+
'app_debug',
71+
'app_env',
72+
'app_force_https',
73+
'app_timezone',
74+
'app_url',
75+
'date_time_app',
76+
'date_time_utc',
77+
'headers',
78+
'hostname',
79+
'ip_address',
4980
'is_trusted_proxy',
81+
'path',
82+
'secure',
83+
'timestamp',
84+
'timezone',
85+
'trusted_proxies',
86+
'url',
5087
]);
5188
}
5289
}

0 commit comments

Comments
 (0)