Skip to content

Instantly share code, notes, and snippets.

@tomsteele
Created March 8, 2013 18:19
Show Gist options
  • Save tomsteele/5118594 to your computer and use it in GitHub Desktop.
Save tomsteele/5118594 to your computer and use it in GitHub Desktop.
simple https to http proxy. useful for meteor projects with force-ssl
var fs = require('fs');
var https = require('https');
var httpProxy = require('http-proxy');
if (!process.env.PROXY_TO_HOST) {
throw new Error('Must set environment variable PROXY_TO_HOST with destination address');
}
if (!process.env.PROXY_TO_PORT) {
throw new Error('Must set environment variable PROXY_TO_PORT with destination port');
}
if (!process.env.PROXY_PORT) {
throw new Error('Must set environment variable PROXY_PORT with port for proxy')
}
if (!process.env.CERT) {
throw new Error('Must set environment variable CERT with path to cert.pem file');
}
if (!process.env.KEY) {
throw new Error('Must set environment variable KEY with path to key.pem file');
}
var options = {
https: {
key: fs.readFileSync(process.env.KEY, 'utf8'),
cert: fs.readFileSync(process.env.CERT, 'utf8')
}
};
var proxy = new httpProxy.HttpProxy({
target: {
host: process.env.PROXY_TO_HOST,
port: process.env.PROXY_TO_PORT
}
});
https.createServer(options.https, function (req, res) {
proxy.proxyRequest(req, res)
}).listen(process.env.PROXY_PORT);
console.log("Proxy listening on " + process.env.PROXY_PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment