Created
March 8, 2013 18:19
-
-
Save tomsteele/5118594 to your computer and use it in GitHub Desktop.
simple https to http proxy. useful for meteor projects with force-ssl
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 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