New Laravel 11 Apps Include a Health Check Endpoint

As part of the release of Laravel 11, new applications include a health /up endpoint. This route is defined in the new bootstrap/app.php file by passing the health parameter—which is defined by default in the Laravel 11 skeleton:

Application::configure(basePath: dirname(__DIR__))
        web: __DIR__.'/../routes/web.php',
        // api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        // channels: __DIR__.'/../routes/channels.php',
        health: '/up', // [tl! add]
    // ...

When setting up the application routing, the Laravel framework defines the health route and also emits a DiagnosingHealth event:

use Illuminate\Foundation\Events\DiagnosingHealth;

// ...

if (is_string($health)) {
    Route::middleware('web')->get($health, function () {
        Event::dispatch(new DiagnosingHealth);

        return View::file(__DIR__.'/../resources/health-up.blade.php');

The route is configurable with the default /up endpoint and returns an animated “Application up” health page in the browser:

Laravel 11 health page
The Laravel 11 health page

The post New Laravel 11 Apps Include a Health Check Endpoint appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

Read more

© 2024 Extly, CB - All rights reserved.