Created
April 5, 2013 12:19
-
-
Save srossross/5318873 to your computer and use it in GitHub Desktop.
Simple http-proxy cli with 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
fs = require('fs'); | |
// Syslog = require('node-syslog'); | |
// Syslog.init("node-syslog", Syslog.LOG_PID | Syslog.LOG_ODELAY, Syslog.LOG_LOCAL0); | |
parser = require("optimist") | |
.alias("r", "router") | |
.demand("router") | |
.boolean('https') | |
.describe('https', 'Use https instead of http') | |
.describe('key', 'Path to keyfile (https only)') | |
.describe('cert', 'Path to cert file (https only)') | |
.alias("h", "help") | |
.alias("p", "port") | |
.default('port', 8080) | |
args = parser.argv | |
if (args.help){ | |
parser.showHelp(); | |
process.exit(-1); | |
} | |
options = { router: require(args.router) } | |
if (args.https) { | |
if (!args.key && !args.cert){ | |
parser.showHelp(); | |
console.log('ERROR: Arguments --key and --cert reqruired when --https is true') | |
process.exit(-1); | |
} | |
options.https = { | |
key: fs.readFileSync(args.key, 'utf8'), | |
cert: fs.readFileSync(args.cert, 'utf8') | |
} | |
} | |
console.log(args.router); | |
server = require("http-proxy").createServer(options); | |
server.listen(args.port); | |
// server.proxy.on('end', function(data1) { | |
// console.log("The request was proxied.", data1.url); | |
// Syslog.log(Syslog.LOG_INFO, "Node Syslog Module output " + new Date()); | |
// }); | |
// ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== | |
http = require('http') | |
http.createServer(function (req, res) { | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
res.write('hello 1\n'); | |
res.end(); | |
}).listen(8001); | |
http.createServer(function (req, res) { | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
res.write('hello 2\n'); | |
res.end(); | |
}).listen(8002); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this file you need the dependancies:
The routing table should be a JSON file like