I am following the upgrade guide to get a Lumen app onto the latest version. The step up to 5.4 breaks routing in the following way.
There is a route at /oauth/test
.
It now results in a 404 (was fine on 5.3):
http://testcase.local/oauth/test
It works if double-nesting the route, as follows:
http://testcase.local/oauth/oauth/test
It is slightly more complex in that the frontend (single page JS) of the application is served behind apache, and the routes that are backend-based are symlinked in. However, apache is configured appropriately (FollowSymLinks) and the configuration worked fine in 5.3.
The routes list out correctly in php artisan route:list
What has changed in 5.4 to break this and how can I fix it?
Edit: The cause is this commit to Lumen.
So something in the way symfony/http-foundation processes symlink-based paths breaks for this use case.
Workaround was to change the logic in the below method:
class Application extends \Laravel\Lumen\Application
{
/**
* This override fixes our routing problem
* https://stackoverflow.com/questions/49048199/upgrading-lumen-from-5-3-to-5-4-breaks-routing-requires-additional-prefix
*
* Parse the incoming request and return the method and path info.
*
* @param \Symfony\Component\HttpFoundation\Request|null $request
* @return array
*/
protected function parseIncomingRequest($request)
{
if (! $request) {
$request = Request::capture();
}
$this->instance(Request::class, $this->prepareRequest($request));
// need the base url as well as the pathinfo when coming from symlinks
return [$request->getMethod(), '/'.trim($request->getBaseUrl() . $request->getPathInfo(), '/')];
}
}