antonioribeiro / health

Laravel Health Panel
BSD 3-Clause "New" or "Revised" License
1.95k stars 197 forks source link

Resources can't be loaded if laravel path contains a prefix #140

Open tpetry opened 5 years ago

tpetry commented 5 years ago

Issue #115 described problems when laravel had been installed to a subfolder. This has been fixed in 0.9.16. But there's still another problem with subfolders if you are using a path prefix which seems not to be fixed the change.

Background: Laravel path prefix

Take for example you have a laravel application at http://example.com/monitoringapp. If you use a webserver like caddy you can point the domain's path prefix monitoringapp to a laravel installation in a specific folder (e.g. /var/www/laravel-monitoring). Everything works correct when you include the path prefix in your .env (APP_URL=http://example.com/monitoringapp):

Problem

The code is using the routes.list[*].uri route path directly for axios to load the information. But this will point to /health/* and not /monitoringapp/health/*. The routes.prefix value can not be changed as described because the route has to be registered without the /monitoringappprefix. So the javascript code can not load the information.

Solution

Use laravel's url helper to generate absolute urls for axios, because it does now how to create the correct one:

tpetry commented 5 years ago

It seems this small code within the HealthController's panel method is enough, but i don't know if there are other places to look for:

$config = config('health');
foreach($config['routes']['list'] as $i => $route) {
    $config['routes']['list'][$i]['uri'] = url($route['uri']);
}

return response((string) view(config('health.views.panel'))->with('laravel', ['health' => $config]));