A simple url router.
Two methods are provided:
router.route(request, response, urls)
urls should be an array of arrays in the from:
urls = [
['/regex', function(request, response){}]
]
Additionally, if your regex contains capture groups, they will be passed as arguments after request and response to your function. For example:
urls = [
['^/media/(.*)$', function(request, response, files){
/* serve file */
}]
]
In this case, if the url /media/img/logo.png is fetched, the argument files would be passed to the function as "img/logo.png".
router.include(urls)
urls should be in the same form as for route. This is used for nesting url lookups. That is all /forum/ urls go to forum.urls and so on. For example:
var router = require('./router');
var forumUrls = require('./forum').urls;
var home = require('./pages').home;
urls = [
['^/$', home],
['^/forum/.*', router.include(forumUrls)]
]