https://github.com/lrlna/reg-router
simple regex router
https://github.com/lrlna/reg-router
Last synced: 7 months ago
JSON representation
simple regex router
- Host: GitHub
- URL: https://github.com/lrlna/reg-router
- Owner: lrlna
- Created: 2017-09-21T14:02:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-21T14:04:11.000Z (about 8 years ago)
- Last Synced: 2025-02-14T21:48:08.043Z (8 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# reg-router
[![npm version][2]][3] [![downloads][8]][9] [![js-standard-style][10]][11]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:
- [bankai](https://github.com/choojs/bankai)
- [choo](https://github.com/choojs/choo)# License
[MIT](https://tldrlegal.com/license/mit-license)[2]: https://img.shields.io/npm/v/reg-router.svg?style=flat-square
[3]: https://npmjs.org/package/reg-router
[8]: http://img.shields.io/npm/dm/reg-router.svg?style=flat-square
[9]: https://npmjs.org/package/reg-router
[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[11]: https://github.com/feross/standard