在Charles这个工具中有一个功能,可以让你映射远程请求:
http://www.charlesproxy.com/documentation/tools/map-remote/
基本上,它可以接收任何针对服务器的请求(即使你不是运行它的人),然后向另一个服务器发出新的请求,保留路径和查询字符串。第二个服务器的响应将覆盖第一个服务器的响应。
我只想知道是否有一个Node模块可以做到这一点。我尝试使用http-proxy,但我觉得这个映射远程工具与代理有点不同,因为似乎你必须拥有两个服务器才能使用代理。
编辑:再次尝试使用http-proxy Node模块,但似乎无法正常工作。以下是我的代码:
var http = require('http')
, httpProxy = require('http-proxy');
httpProxy.createServer({
hostnameOnly: true,
router: {
'www.stackoverflow.com': 'localhost:9000',
}
}).listen(80);
// Create your target server
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
我的期望是,当我访问www.stackoverflow.com或www.stackoverflow.com:80时,它会重定向到我的localhost:9000
www.stackoverflow.com
指向你的Node.js服务器的IP地址? - Brad