Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Open
wants to merge 1 commit into from

4 participants

@samholmes

I believe the added algorithm at line 16 would allow for "*.mydomain.com" routes to be matched by "www.mydomain.com", "foobar.mydomain.com", etc.

@substack
Owner

I bet there is a wildcard module somewhere that has a more robust and well-tested recursive algorithm for this. Or perhaps fall into regex mode if the first and last characters in the key are '/'.

@samholmes

Could maybe do both. A regex syntax would be great for real advanced pattern matching. While a simple wildcard syntax would be great too for the regular matching.

I've tested the changes with ".mydomain.com". It matches "www.mydomain.com" and "www.shop.mydomain.com". I've also tried ".shop.mydomain.com" which matches "www.shop.mydomain.com" and "www.my.shop.mydomain.com", but not "www.mydomain.com". You should try it out as well.

@keverw

This would be a nice feature! Like I have it go to my WordPress Network install, so for each new subdomain, I have to add to the routes.json file.

@contra

I think isaacs minimatch module would be a good fit for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 1 deletion.
  1. +9 −1 bin/bouncy.js
View
10 bin/bouncy.js
@@ -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
Something went wrong with that request. Please try again.