Node.js HTTPS proxy not working

I would like to create a proxy for HTTPS connections with Node.js. I am using the http-proxy library which works well. I can make the HTTP proxy work fine, but when I try HTTPS , the proxy request just expires. Here is my code (a slightly modified version of the node-http-proxy proxy-https-to-https example):

 var http = require("http"), https = require("https"), httpProxy = require("http-proxy"), fs = require('fs'); var httpsConfig = { key: fs.readFileSync('./jackos2500-key.pem'), cert: fs.readFileSync('./jackos2500-cert.crt'), }; https.createServer(httpsConfig, function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('hello https\n'); res.end(); }).listen(8000); httpProxy.createServer(8000, 'localhost', { https: httpsConfig, target: { https: true, rejectUnauthorized: false } }).listen(443); 

Is there something obvious I'm missing here or is there another problem?

+4
source share
2 answers

I have the same problem. I do not see anything. Here is mine, which is slightly different (the second one corresponds to the examples that I see from the github examples):

 var https = require('https'); var httpProxy = require('http-proxy/lib/node-http-proxy'); var helpers = require('http-proxy/test/helpers'); var request = require('request'); https.createServer(function(req, response) { try { console.log("forwarding https", req); var proxy_request = request(req); proxy_request.pipe(response); } catch (err) { console.log("Forwarding server caught error:\n" + err + "\n") } }).listen(9001); httpProxy.createServer(function (req, res, proxy) { console.log("Got request!"); proxy.proxyRequest(req, res, { port: 9001, host: 'localhost', buffer: httpProxy.buffer(req) }); }, { https: helpers.https }).listen(8001); 

... I also tried a simpler one:

 httpProxy.createServer(9001, 'localhost', { https: helpers.https }).listen(8001) 

When I set the Firefox https proxy port to 8001 and go anywhere, I get "The connection was reset."

I do the same with "http", replacing "https" and everything works fine.

0
source
0
source

All Articles