Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple router for node.js
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
Makefile
README.md
index.js
package.json

README.md

daleth*

Daleth is very simple router.

*In the Phoenician alphabet "Daleth" indicates door.

Installation

You can install daleth as usual - by copy "daleth" directory in your ~/.node_libraries or via npm

npm install daleth

Usage

Usage of daleth is very simple:

var http = require('http');
var daleth = require('daleth')(
    [/^\/([a-z]+)\/?$/, function(request, response, args) {
        response.writeHead(200, {'Content-Type': 'text/html'});
        response.end('One argument: ' + args, 'utf8');
    }],
    [/^\/$/, function(request, response) {
        response.writeHead(200, {'Content-Type': 'text/html'});
        response.end('Pure root', 'utf8');
    }],
    [/^\/.*$/, function(request, response) { // Fallback
        response.writeHead(404, {'Content-Type': 'text/html'});
        response.end('Not found', 'utf8');
    }]
);

http.createServer(function (request, response) {
    daleth(request.url, function(handler, args) {
        handler(request, response, args);
    });
}).listen(8888);

daleth takes set of two-element arrays that contains regex and handler as arguments and returns "route" function. Regex is full JavaScript RegExp object that can include "search groups". Handler can be any object, not just a function.

"Route" function takes two arguments: path and callback. Callback also takes two arguments: routed handler and array of extracted matching search groups. If path includes "?" symbol, daleth trashes it and all trailing path.

Something went wrong with that request. Please try again.