-
-
Save chapel/0b10b44fe4cddb23b782 to your computer and use it in GitHub Desktop.
Gist created using https://github.com/niftylettuce/gedit-gists
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
// # 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