reg-router
simple regex router
Last updated 3 years ago by lrlna .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install reg-router 
SYNC missed versions from official npm registry.

reg-router

npm version downloads js-standard-style

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.

Related content:

License

MIT

Current Tags

  • 1.0.1                                ...           latest (3 years ago)

1 Versions

  • 1.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 4
Dependencies (0)
None
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |