我正在开发一个node.js
代理服务器应用程序,我希望它支持HTTP
和HTTPS(SSL)
协议(作为服务器)。node.js中的HTTPS代理服务器
我目前使用node-http-proxy
这样的:
const httpProxy = require('http-proxy'),
http = require('http');
var server = httpProxy.createServer(9000, 'localhost', function(req, res, proxy) {
console.log(req.url);
proxy.proxyRequest(req, res);
});
http.createServer(function(req, res) {
res.end('hello!');
}).listen(9000);
server.listen(8000);
设置我的浏览器使用HTTP
代理上localhost:8000
和它的作品。我也想抓HTTPS
请求(即设置我的浏览器使用localhost:8000
作为HTTPS
代理以及捕获我的应用程序中的请求)。你能帮我吗我该怎么做?
PS:
如果我订阅upgrade
事件httpProxy
服务器对象的我能得到请求,但我不知道如何将请求转发和发送响应客户端:
server.on('upgrade', function(req, socket, head) {
console.log(req.url);
// I don't know how to forward the request and send the response to client
});
任何帮助,将不胜感激。
该要点的链接已过时。我已经更新到https://gist.github.com/ncthis/6863947 – david
@david再次过时 – fidev
'httpProxy.HttpProxy不是函数' –