unmon-router
v1.0.1
Published
a minimalist, express-like router
Downloads
3
Readme
'Said Ummon to his disciples,
"However wonderful a thing is,
it may be that it is better
not to have it at all."
unmon-router
a minimalist, express-like router
Unmon-router implements a lightweight, middleware router. Its api makes it compatible with most express middleware.
Usage
var http = require('http');
var unmon = require('unmon-router');
var app = unmon();
// log all request URLs
app.route(/.*/, function (req, res, next) {
console.log(req.url);
next();
});
// handle API requests
app.route(/^\/api\//, function (req, res, next) {
res.end('{}');
});
// serve 404s for everything else
app.route(/.*/, function (req, res) {
res.statusCode = 404;
res.end('404');
});
http.createServer(app.compile()).listen(3007);
API
The above example illustrates the basic API.
- initialize an app.
- push middleware to a stack with
app.route
.
- unlike express, unmon expects the url pattern to be a regex, not a string
- the middleware function should use the
(request, response, callback)
signature
- compile the app and pass it to the http module.
Install
With npm installed, run
$ npm install unmon-router
Acknowledgments
unmon-router was inspired by Expressjs.
License
ISC