Last active
August 29, 2015 13:58
-
-
Save tatat/10252252 to your computer and use it in GitHub Desktop.
かんたん http proxy
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
#!/usr/bin/env node | |
var fs = require('fs') | |
, http_proxy = require('http-proxy') | |
, http = require('http') | |
, https = require('https') | |
, cert_file_path = '/path/to/server.crt' | |
, key_file_path = '/path/to/server.key'; | |
var proxy = http_proxy.createProxyServer(); | |
http.createServer(function(req, res) { | |
proxy.web(req, res, { target: "http://localhost:3000" }); | |
}).listen(3030); | |
console.log("Listening http://localhost:3030"); | |
https.createServer({ | |
cert: fs.readFileSync(cert_file_path, "utf8") | |
, key: fs.readFileSync(key_file_path, "utf8") | |
}, function(req, res) { | |
req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.socket.remoteAddress; | |
req.headers['x-forwarded-port'] = "3031"; | |
req.headers['x-forwarded-proto'] = "https"; | |
proxy.web(req, res, { target: "http://localhost:3000" /*, xfwd: true */ }); | |
}).listen(3031); | |
console.log("Listening https://localhost:3031"); | |
process.on('uncaughtException', function(exception) { | |
console.error(exception); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment