Skip to content

Instantly share code, notes, and snippets.

@coderarity
Created January 6, 2013 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderarity/1118bd5a0e4e4cd861f1 to your computer and use it in GitHub Desktop.
Save coderarity/1118bd5a0e4e4cd861f1 to your computer and use it in GitHub Desktop.
var http = require('http'),
httpProxy = require('http-proxy'),
path = require("path"),
fs = require("fs"),
crypto = require("crypto");
//
// generic function to load the credentials context from disk
//
function getCredentialsContext (cer) {
return crypto.createCredentials({
key: fs.readFileSync(path.join(__dirname, 'certs', cer + '.key')),
cert: fs.readFileSync(path.join(__dirname, 'certs', cer + '.crt'))
}).context;
}
//
// A certificate per domain hash
//
var certs = {
"testone.com": getCredentialsContext("testone.com"),
"testtwo.com": getCredentialsContext("testtwo.com")
};
//
// Proxy options
//
var options = {
https: {
SNICallback: function(hostname){
return certs[hostname];
}
},
hostnameOnly: true,
router: {
'testone.com': '127.0.0.1:8001',
'testtwo.com': '127.0.0.1:8002'
}
};
//
// Create a standalone HTTPS proxy server
//
httpProxy.createServer(options).listen(443);
//
// Create the target HTTPS servers
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('hello https\n');
res.end();
}).listen(8001);
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('hello https 2\n');
res.end();
}).listen(8002);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment