Skip to content

Instantly share code, notes, and snippets.

@tatat
Last active August 29, 2015 13:58
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 tatat/10252252 to your computer and use it in GitHub Desktop.
Save tatat/10252252 to your computer and use it in GitHub Desktop.
かんたん http proxy
#!/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