这是我第一次尝试使用http-proxy。我得到了一个错误:
Error: Must provide a proper URL as target
代码:
httpProxy = require('http-proxy');
httpProxy.createServer(function(req, res) {
proxy.web(req, res, { target: 'http://127.0.0.1:10002' });
}).listen(3001);
我从curl那里知道我的网站在10002端口上运行。
正确的URL是什么样子的?或者这个错误实际上意味着完全不同的东西?端口10002开箱后无法访问,我正在通过Internet对其进行测试。
发布于 2019-12-08 08:09:40
您需要使用http
模块而不是http-server
创建服务器。
用require('http').createServer
替换httpProxy.createServer
:
const httpProxy = require('http-proxy')
const proxy = httpProxy.createProxyServer({}) // I added this line to make this full snippet working
require('http').createServer(function (req, res) {
proxy.web(req, res, { target: 'http://127.0.0.1:10002' })
}).listen(3001)
https://stackoverflow.com/questions/59231093
复制相似问题