airbnb/rendr — pull request #147 by bigethan (2013-10-16 20:50:37+00:00)
Title: Adding checks for routes using regexes.

[Re-pull of https://github.com/airbnb/rendr/pull/145 which accidentally got a ton of history "changed"]

the routes still need to be prepared a bit due to express using a leading `/` and backbone
not using the leading slash. So even with this, the routes file has some logic:

```javascript
//app/routes.js

//backbone style regex, no leading slash
var routes =
[
['', 'getHome', 'home#index'],
[/^foo.*/, 'getFoo', 'foo#index'],
[/^bar.*/, 'getBar', 'bar#index']
];

module.exports = function(match) {
routes.forEach( function(el, i){
pattern = el[0];
if(el[0] instanceof RegExp) {
if(this.isServer) {
//add the leading / for express if the regex is looking at the start of the path
pattern = new RegExp(routeArray[0].toString().slice(1,-1).replace(/^\^/, '^\\\/'));
}
}
match(pattern, el[1], el[2]);
});
};
```

This logic could be moved into the `shared/base/router.js` buildRoutes:captureRoutes method:

```javascript
//rendr/shared/base/router.js

function captureRoutes() {
var routeArray = _.toArray(arguments);

if(routeArray[0] instanceof RegExp) {
if(this.isServer) {
//add the leading / for express if the regex is looking at the start of the path
routeArray[0] = new RegExp(routeArray[0].toString().slice(1,-1).replace(/^\^/, '^\\\/'));
}
}
routes.push(routeArray);
}
```

but didn't want to suggest too much, plus this feels juuust a little weird. Just wanted to
get regex routes to get though the flow.