我正在关注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处理基于符号链接的路径的方式会破坏此用例。
答案 0 :(得分:0)
解决方法是更改以下方法中的逻辑:
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(), '/')];
}
}