Update /bin/bouncy.js to support wildcard characters (*) for sub-domains... #29

Open
wants to merge 1 commit into
from
View
@@ -13,7 +13,15 @@ var config = JSON.parse(fs.readFileSync(configFile));
var bouncy = require('bouncy');
bouncy(function (req, bounce) {
var host = (req.headers.host || '').replace(/:\d+$/, '');
- var route = config[host] || config[''];
+ for (var i in config)
+ {
+ var pattern = '^'+i.replace(/\*\./g, '(\\w*\\.)*').replace(/\\?\./g, '\\.');
+ if (host.search(pattern) != -1)
+ {
+ var route = config[i];
+ break;
+ }
+ }
if (Array.isArray(route)) {
// jump to a random route on arrays