-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Description
Laravel Version
11.35.0
PHP Version
8.3.14
Database Driver & Version
No response
Description
Follow up for #53772
This implementation does work, but only if you don't use php artisan optimize
or php artisan route:cache
If you cache routes, then route definitions are restored from the cache. (check the first code snipped in the spoiler below)
And the closure that eventually excludes a health route from maintenance mode will never be executed.
Closure execution (spoiler)
framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php
Lines 56 to 59 in 3903c5d
if ($this->routesAreCached()) { | |
$this->loadCachedRoutes(); | |
} else { | |
$this->loadRoutes(); |
framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php
Lines 159 to 162 in 3903c5d
protected function loadRoutes() | |
{ | |
if (! is_null(self::$alwaysLoadRoutesUsing)) { | |
$this->app->call(self::$alwaysLoadRoutesUsing); |
framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php
Lines 98 to 101 in 3903c5d
public static function loadRoutesUsing(?Closure $routesCallback) | |
{ | |
self::$alwaysLoadRoutesUsing = $routesCallback; | |
} |
framework/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Lines 162 to 166 in 3903c5d
if (is_null($using) && (is_string($web) || is_array($web) || is_string($api) || is_array($api) || is_string($pages) || is_string($health)) || is_callable($then)) { | |
$using = $this->buildRoutingCallback($web, $api, $pages, $health, $apiPrefix, $then); | |
} | |
AppRouteServiceProvider::loadRoutesUsing($using); |
framework/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Lines 194 to 215 in 3903c5d
protected function buildRoutingCallback(array|string|null $web, | |
array|string|null $api, | |
?string $pages, | |
?string $health, | |
string $apiPrefix, | |
?callable $then) | |
{ | |
return function () use ($web, $api, $pages, $health, $apiPrefix, $then) { | |
if (is_string($api) || is_array($api)) { | |
if (is_array($api)) { | |
foreach ($api as $apiRoute) { | |
if (realpath($apiRoute) !== false) { | |
Route::middleware('api')->prefix($apiPrefix)->group($apiRoute); | |
} | |
} | |
} else { | |
Route::middleware('api')->prefix($apiPrefix)->group($api); | |
} | |
} | |
if (is_string($health)) { | |
PreventRequestsDuringMaintenance::except($health); |
Steps To Reproduce
- Run
php artisan optimize
- Put site in maintenance mode
php artisan down
- Open health route