我正在使用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。
答案 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);
});