Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Move configuration to a separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dansimau committed May 17, 2011
1 parent 8d057a3 commit fcc6c69
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cache/
proxy.conf
30 changes: 20 additions & 10 deletions proxy.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
var util = require('util');
var http_proxy = require('./lib/proxy');
var fs = require('fs');

// Configuration - TODO: move to config file
var listen_port = 80;
var configFile = __dirname + '/proxy.conf';
var conf = {};

var proxy = http_proxy.createServer({
"targetHost": "213.129.83.20",
"targetPort": "80",
cache: {
maxMem: 16
}
}).listen(listen_port);
util.log("master: Listening on port " + listen_port);
try {
conf = JSON.parse(fs.readFileSync(configFile, 'utf8'));
}
catch (err) {
util.log('Unable to read configuration from file (' + configFile + ').');
util.log('Check that the file exists and syntax is correct.');
process.exit(1);
}

for (var i = 0, l = conf.length; i < l; i++) {
var listen_port = conf[i].port;
var proxy = http_proxy.createServer(
conf[i].proxy
).listen(conf[i].port, function() {
util.log("Listening on port " + listen_port);
});
}

0 comments on commit fcc6c69

Please sign in to comment.