A URL router for node.js
JavaScript
Switch branches/tags
Nothing to show
Latest commit 66d661a May 2, 2011 defrex added npm package file
Permalink
Failed to load latest commit information.
README.md update to README Dec 15, 2009
package.json added npm package file May 2, 2011
routes.js Return true if url matched or false if unmatched Oct 14, 2010

README.md

node.routes.js

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)]
]