Skip to content

Commit

Permalink
option parsing for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Jun 21, 2012
1 parent 4631502 commit 1c4a6ce
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions server.js
@@ -1,9 +1,53 @@
var spdy = require('spdy'),
http = require('http'),
path = require('path'),
url = require('url'),
net = require('net'),
fs = require('fs');

var opts = require('optimist')
.usage('Usage: $0 -x - y')
.options({
key: {
demand: true,
alias: 'k',
description: 'path to SSL key'
},
cert: {
demand: true,
alias: 'c',
description: 'path to SSL certificate'
},
ca: {
demand: true,
alias: 'a',
description: 'path to SSL CA certificate'
},
port: {
demand: false,
alias: 'p',
description: 'proxy port',
default: 44300
},
user: {
demand: false,
alias: 'u',
description: 'basich auth username'
},
pass: {
demand: false,
alias: 'p',
description: 'basic auth password'
}
})
.argv;

opts.key = fs.readFileSync(path.resolve(opts.key));
opts.cert = fs.readFileSync(path.resolve(opts.cert));
opts.ca = fs.readFileSync(path.resolve(opts.ca));



process.on('uncaughtException', function(e) {
console.error('Error: ' + e);
});
Expand Down Expand Up @@ -103,13 +147,7 @@ function handleRequest(req, res) {
}
}

var serverOptions = {
key: fs.readFileSync(__dirname + '/keys/mykey.pem'),
cert: fs.readFileSync(__dirname + '/keys/mycert.pem'),
ca: fs.readFileSync(__dirname + '/keys/mycsr.pem')
};

var server = spdy.createServer(serverOptions);
var server = spdy.createServer(opts);

server.on("request", handleRequest);
server.on("connect", handleRequest);
Expand Down

0 comments on commit 1c4a6ce

Please sign in to comment.