Skip to content

Instantly share code, notes, and snippets.

@chapel

chapel/bouncy.js Secret

Forked from anonymous/bouncy.js
Created March 20, 2012 00:29
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 chapel/0b10b44fe4cddb23b782 to your computer and use it in GitHub Desktop.
Save chapel/0b10b44fe4cddb23b782 to your computer and use it in GitHub Desktop.
// # Bouncy
var bouncy = require('bouncy')
, fs = require('fs')
, path = require('path')
, servers = {}
fs.watchFile(path.join(__dirname, 'servers.json'), function(curr, prev) {
console.log("Watching servers.json");
if (curr.mtime.getTime() !== prev.mtime.getTime()) {
fs.readFile(path.join(__dirname, 'servers.json'), 'utf8', function(err, data) {
if (err) {
console.log(err);
} else {
servers = JSON.parse(data);
console.log(servers);
}
});
}
});
bouncy(function(req, bounce) {
console.log("Host: ", req.headers.host);
// Run through each property and value
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