-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add health endpoint (resolves #1410)
- Loading branch information
1 parent
d1adfcd
commit 4f2b96a
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Foundation\Events\DiagnosingHealth; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Event; | ||
|
||
class HealthController extends Controller | ||
{ | ||
public function show(Request $request): JsonResponse | ||
{ | ||
$status = []; | ||
|
||
Event::dispatch(new DiagnosingHealth); | ||
|
||
if (defined('LARAVEL_START')) { | ||
$status['duration'] = round((microtime(true) - LARAVEL_START) * 1000).'ms'; | ||
} | ||
|
||
return response()->json($status); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Illuminate\Testing\Fluent\AssertableJson; | ||
|
||
use function Pest\Laravel\get; | ||
|
||
test('health page loads without response', function () { | ||
get(route('health')) | ||
->assertOk() | ||
->assertJson(fn (AssertableJson $json) => $json->missing('duration') | ||
); | ||
}); | ||
|
||
test('health page loads with response', function () { | ||
define('LARAVEL_START', microtime(true)); | ||
|
||
get(route('health')) | ||
->assertOk() | ||
->assertJson(fn (AssertableJson $json) => $json->has('duration') | ||
); | ||
}); |