将流明从5.3升级到5.4会中断路由 - 需要额外的前缀

问题描述 投票:0回答:1

我正在关注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处理基于符号链接的路径的方式会破坏此用例。

php laravel laravel-5.4 lumen-5.4
1个回答
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(), '/')];
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.