17611538698
webmaster@21cto.com

新的 Laravel 11 应用将包含健康检查节点

资讯 0 290 2024-02-15 02:08:11

图片

作为Laravel 11版本的一部分,新应用程序包含了一个新的健康检查节点:

/up

该路由是通过健康检查参数传递,是在位于新的bootstrap/app.php文件中所定义的。

目前该参数在 Laravel 11 框架中默认被定义:

 Application::configure(basePath: dirname(__DIR__))
->withProviders()
->withRouting(
web: __DIR__.'/../routes/web.php',
// api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
// channels: __DIR__.'/../routes/channels.php',
+ health: '/up',
)
// ...


设置应用程序路由时,Laravel 框架定义健康检查路由会发出一个DiagnosingHealth事件:

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');
});
}


该路由可使用默认/up节点进行配置,并在浏览器中返回一个动画效果的“Application up”运行状况页面:

图片

Laravel 11 健康检查页面


作者:万能的大雄

评论