8000 Health endpoint is stripped out when defining routes with "using" keywork · Issue #55739 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

Health endpoint is stripped out when defining routes with "using" keywork #55739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
darioriverat opened this issue May 14, 2025 · 3 comments
Open

Comments

@darioriverat
Copy link

Laravel Version

12.x

PHP Version

8.4

Database Driver & Version

No response

Description

Laravel comes with a built-in health check endpoint on /up, which is defined in the bootstrap/app.php file as an argument of the withRouting method. In specific circumstances, this endpoint is stripped out, in particular, when routes are defined utilizing the "using" parameter as an alternative to "web".

Current Behaviour

When running php artisan route:list in a fresh Laravel app, you get something similar to the following

GET|HEAD       / ......................................
GET|HEAD       storage/{path} ........... storage.local
GET|HEAD       up .....................................

When defining routes with the "using" parameter, the health check endpoint is removed from the routes, as we can observe by executing the route list again.

GET|HEAD       / ......................................
GET|HEAD       storage/{path} ........... storage.local

Expected Behaviour

The health check endpoint is perverse regardless of the way routes are defined, either utilizing web or using as an argument for withRouting.

Steps To Reproduce

  1. Create a fresh Laravel installation (e.g., laravel new my-app).
  2. Open the bootstrap/app.php file.
  3. Locate the default Application::configure(...)->withRouting(...) block:
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(...)
    ->withExceptions(...)
    ->create();
  1. Run php artisan route:list and confirm the presence of the /up health check route.
  2. Modify the withRouting configuration by replacing the web file with an inline route using the using parameter:
->withRouting(
    using: function (Application $app) {
        Route::get('/', function () {
            return view('welcome');
        });
    },
    // web: __DIR__.'/../routes/web.php', <-- remove or comment out
    commands: __DIR__.'/../routes/console.php',
    health: '/up',
)
  1. Run php artisan route:list again.
@darioriverat darioriverat changed the title Health endpoint is strip out when defining routes with "using" keywork Health endpoint is stripped out when defining routes with "using" keywork May 14, 2025
@rodrigopedra
Copy link
Contributor

That is expected, as per docs:

you may even take complete control over route registration by providing a using closure to the withRouting method. When this argument is passed, no HTTP routes will be registered by the framework and you are responsible for manually registering all routes

Reference: https://laravel.com/docs/12.x/routing#routing-customization

Apart from $commands and $channels, all other parameters are ignored when a \Closure is provided within the $using argument.

@darioriverat
Copy link
Author

@rodrigopedra , thanks for finding that piece of documentation. I acknowledge that documentation is clear in that sense. However, the interface of withRouting looks a bit ambiguous when allowing to take full control with using but also accepting health.

It might be that the health check endpoint is intended as an exception to the rule. Let’s wait for @taylorotwell 's input to see if that was the intended design. I've also created a pull request with a potential solution in case it's decided to treat health as a special case while maintaining consistency with the using approach.

@rodrigopedra
Copy link
Contributor

However, the interface of withRouting looks a bit ambiguous when allowing to take full control with using but also accepting health.

IMHO, there is no ambiguity, as long one has read the docs.

But I also agree it would be a nice addition to allow registering the health route along with the $using callback.

Fingers crossed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0