Skip to content
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

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

Open
tpetry opened this issue Dec 14, 2018 · 1 comment
Open

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

tpetry opened this issue Dec 14, 2018 · 1 comment

Comments

@tpetry
Copy link

tpetry commented Dec 14, 2018

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):

  • Routes are registered with /health/check because the /monitoringapp prefix must not be used when registering routes! (laravel will "ignore" the /monitoringapp when routing)
  • The routes are correctly accessible, they resolve to the correct controller.
  • No problem at this point :)

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:

  • config('health.routes.list[0].uri') => /health/panel WRONG
  • route(config('health.routes.list[0].name')) => http://example.com/monitoringapp/health/panel CORRECT
    Using the url-helper to generate the url for axios may probably solve many more problems with "esoteric" configurations how urls are mapped within laravel because it's relying on the same logic every url is routed within laravel.
@tpetry
Copy link
Author

tpetry commented Dec 14, 2018

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]));

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

1 participant