0

我正在按照升级指南将 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 中发生了什么改变来打破这个问题,我该如何解决?

编辑:原因是对 Lumen的承诺。

所以 symfony/http-foundation 处理这个用例的基于符号链接的路径中断的方式。

4

1 回答 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(), '/')];
    }
}
于 2018-03-01T12:34:46.437 回答