Skip to content

Commit 597f77e

Browse files
authored
[11.x] The health route should be loaded even when there is a model binding at the root (#50165)
* make sure the "health" route is loaded before the web routes. * style: fixes.
1 parent 58e4234 commit 597f77e

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

src/Illuminate/Foundation/Configuration/ApplicationBuilder.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ protected function buildRoutingCallback(?string $web,
171171
Route::middleware('api')->prefix($apiPrefix)->group($api);
172172
}
173173

174+
if (is_string($health)) {
175+
Route::middleware('web')->get($health, function () {
176+
Event::dispatch(new DiagnosingHealth);
177+
178+
return View::file(__DIR__.'/../resources/health-up.blade.php');
179+
});
180+
}
181+
174182
if (is_string($web) && realpath($web) !== false) {
175183
Route::middleware('web')->group($web);
176184
}
@@ -181,14 +189,6 @@ class_exists(Folio::class)) {
181189
Folio::route($pages, middleware: $this->pageMiddleware);
182190
}
183191

184-
if (is_string($health)) {
185-
Route::middleware('web')->get($health, function () {
186-
Event::dispatch(new DiagnosingHealth);
187-
188-
return View::file(__DIR__.'/../resources/health-up.blade.php');
189-
});
190-
}
191-
192192
if (is_callable($then)) {
193193
$then($this->app);
194194
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Foundation\Support\Providers;
4+
5+
use Illuminate\Foundation\Application;
6+
use Illuminate\Support\Str;
7+
use Orchestra\Testbench\TestCase;
8+
9+
class RouteServiceProviderHealthTest extends TestCase
10+
{
11+
/**
12+
* Resolve application implementation.
13+
*
14+
* @return \Illuminate\Foundation\Application
15+
*/
16+
protected function resolveApplication()
17+
{
18+
return Application::configure(static::applicationBasePath())
19+
->withRouting(
20+
web: __DIR__.'/fixtures/web.php',
21+
health: '/up',
22+
)->create();
23+
}
24+
25+
protected function defineEnvironment($app)
26+
{
27+
$app['config']->set('app.key', Str::random(32));
28+
}
29+
30+
public function test_it_can_load_health_page()
31+
{
32+
$this->get('/up')->assertOk();
33+
}
34+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
Route::get('/{user}', fn () => response('', 404));

0 commit comments

Comments
 (0)