-
-
Save coderarity/683ff1fc13ca883b9989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var https = require('https'), | |
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 = { | |
"fobar.com": getCredentialsContext("foobar"), | |
"barbaz.com": getCredentialsContext("barbaz") | |
}; | |
// | |
// Proxy options | |
// | |
var options = { | |
https: { | |
SNICallback: function(hostname){ | |
return certs[hostname]; | |
} | |
}, | |
hostnameOnly: true, | |
router: { | |
'fobar.com': '127.0.0.1:8001', | |
'barbaz.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