Skip to content

Instantly share code, notes, and snippets.

@cs8425
Last active October 3, 2015 05:46
Show Gist options
  • Save cs8425/dd3d5b7553094e05a197 to your computer and use it in GitHub Desktop.
Save cs8425/dd3d5b7553094e05a197 to your computer and use it in GitHub Desktop.
simple http to https proxy (with ws)
var fs = require('fs');
var http = require('http');
var https = require('https');
var httpProxy = require('http-proxy');
http.globalAgent.maxSockets = 10000;
https.globalAgent.maxSockets = 10000;
var options = {
https: {
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt'),
}
};
// this is the target server
var proxy = new httpProxy.createProxyServer({
target: {
host: '127.0.0.1',
port: 80
}
});
proxy.on('error', function(e) {
console.log('proxy Error', e);
});
var proxyServer = https.createServer(options.https, function (req, res) {
proxy.web(req, res);
});
proxyServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});
proxyServer.listen(443, function(err) {
if (err) console.log('Error', err);
console.log(proxy);
console.log('Created https proxy. Forwarding requests from %s to %s:%s', '443', '127.0.0.1', 80);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment