reg-router
v1.0.1
Published
simple regex router
Downloads
4
Readme
reg-router
Just your reg router to match routes based on provided regex.
Usage
var router = require('reg-router')()
router.route(/^\/reset$/, function (req, res, params) {
res.writeHead(200, 'reset route is hit', { 'content-encoding': 'application/json' })
}
http.createServer(function (req, res) {
router.match(req, res)
}).listen(8080)
API
router = new Router()
Creates a new instance off reg-router.
router.route(regex, handler)
Register a new route. Handler is generally req, res, params
.
router.default(handler)
Defaults to sending back a 404, but you can provide your own default. router.default
will do this for you.
router.match(req, res)
Match requests to registered routes. Would usually use when server's fired up.