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 get a HTTP
proxy to work perfectly, but when I try HTTPS
, the request to the proxy just times out. 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 some other issue?