瘦代理重定向到VueJS本地主机服务器

时间:2019-08-11 11:29:24

标签: php apache vue.js slim

我正在使用PHP SLIM框架,并且我想为开发目的在本地主机(服务器端)上提供vuejs dev服务器。

我想做这样的事情:

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

这不起作用,实际上只是告诉客户端寻找该URI。

我想要什么: enter image description here

我得到了什么: enter image description here

1 个答案:

答案 0 :(得分:0)

您的问题很难理解,但是我想您尝试通过Slim在*.vue上渲染/编译vuejs/vue-dev-server文件。

这是使用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);
});