EasyAdminBundle
EasyAdminBundle copied to clipboard
[4.9.1] Action::linkToRoute does not handle reverse proxy context
Describe the bug The request handling of a custom action created with the linkToRoute method does not work as expected if the app is behind a reverse proxy.
Context
- My app is behind reverse proxy. So when accessing https://rp-domain.com/my-app, the reverse proxy redirects all requests to https://app-domain.com/
- Symfony handles well the reverse proxy settings: it will detect the URI prefix (/my-app) and will not consider it during routing process.
To Reproduce
- In standard CRUD Controller, create custom action and use linkToRoute() to specify the target based on an existing route.
- Go on your app and click on the link.
- Here, src/EventListener/AdminRouterSubscriber.php will detect the route name from the query string and will generate the url. If behind a reverse proxy, the url will contain the uri prefix /my-app.
- As you can see in the screenshot below, the REQUEST_URI will be set with this url, but it should not include the uri prefix
(OPTIONAL) Additional context
Possible solutions 1. Instead of generate the url to detect the controller to call, we could rely on routes configuration:
$routes = $this->get('router')->getRouteCollection();
$controller = $routes->get($routename)->getDefaults()['_controller'];
Why don't we just forward the request to the route name ?
Like AbstractController::forward() method
?
Instead of creating the link like /admin?routeName=app_my_route
, generate the right url: /my-route
Workaround:
Instead of using linkToRoute('app_my_route')
, I use linkToUrl($this->generateUrl('app_my_route'))