【问题标题】:Slim proxy redirection to VueJS localhost serverSlim 代理重定向到 VueJS localhost 服务器
【发布时间】:2019-12-18 08:22:07
【问题描述】:

我正在使用 PHP SLIM 框架,我想在 localhost(服务器端)上为开发目的提供一个 vuejs dev 服务器。

我想做这样的事情:

$app->get('/dev/vuejs', function (Request $request, Response $response, array $args) {
    return $response->withRedirect("http://127.0.0.1:8080");
});

这不像我想的那样工作,实际上只是告诉客户端寻找那个 URI。

我想要什么:

我得到了什么:

【问题讨论】:

  • 你的问题不清楚。请描述您想要什么,让我们知道您提供的代码有什么问题。

标签: php apache vue.js slim


【解决方案1】:

你的问题很难理解,但我猜你试图通过 vuejs/vue-dev-server 上的 Slim 渲染/编译 *.vue 文件。

这是一个使用 curl 的概念证明:

$app->get('/dev/vuejs', function (Request $request, Response $response, array $args) {
    // Change the url here
    $url = 'http://127.0.0.1:8080';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    $responseBody = curl_exec($ch);
    if ($responseBody === false) {
        $response->getBody()->write('HTTP error: ' . curl_error($ch));

        return $response->withStatus(500);
    }

    $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $responseBody = trim(substr($responseBody, $headerSize));
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);

    $response->getBody()->write($responseBody);

    return $response->withStatus($httpCode);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多