我正在关注upgrade guide以获得最新版本的Lumen应用程序。 5.4的步骤以下列方式中断路由。
在/oauth/test
有一条路线。
它现在导致404(在5.3上罚款):http://testcase.local/oauth/test
如果双重嵌套路由,它可以工作,如下所示:
http://testcase.local/oauth/oauth/test
它稍微复杂一点,因为应用程序的前端(单页JS)是在apache后面提供的,并且基于后端的路由是符号链接的。但是,apache已正确配置(FollowSymLinks)并且配置在5.3中正常工作。
这些路线在php artisan route:list
中正确列出
在5.4中有什么改变来打破这个并且我该如何解决它?
编辑:原因是this commit到流明。
因此,symfony / http-foundation处理基于符号链接的路径的方式会破坏此用例。
解决方法是更改以下方法中的逻辑:
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(), '/')];
}
}