Skip to content

Instantly share code, notes, and snippets.

/bouncy.js Secret

Created March 20, 2012 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8fddb7eab4526a70b14e to your computer and use it in GitHub Desktop.
Save anonymous/8fddb7eab4526a70b14e to your computer and use it in GitHub Desktop.
// # Bouncy
var bouncy = require('bouncy')
, fs = require('fs')
, path = require('path');
fs.watchFile(path.join(__dirname, 'servers.json'), function(curr, prev) {
console.log("Watching servers.json");
if (curr.mtime.getTime() !== prev.mtime.getTime()) {
bouncy(function(req, bounce) {
console.log("Host: ", req.headers.host);
// Run through each property and value
fs.readFile(path.join(__dirname, 'servers.json'), 'utf8', function(err, data) {
if (err) {
console.log(err);
} else {
var servers = JSON.parse(data);
console.log(servers);
if (req.headers.host in servers) {
bounce(servers[req.headers.host]);
} else {
bounce(8081);
}
}
});
}).listen(8000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment