JSPM

micro-server-router

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q38730F
  • License MIT

Server router for Micro

Package Exports

  • micro-server-router

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (micro-server-router) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

micro-server-router

Performant radix-trie router for Zeit's Micro.

Fork of yoshuawuyts' server-router, modified for compatibility with Micro.

Usage

const MicroServerRouter = require('micro-server-router')

const router = new MicroServerRouter()

router.route('POST', '/hello', () => 'world')
router.route('GET', '*', () => 'nothing')

module.exports = router.start()

API

router = new MicroSeverRouter(opts)

Create a new router with opts.

router.route(method|routes, route, function(req, res, params))

Register a new route with an HTTP method name and a routename. Can register multiple handlers by passing an array of method names. params contains matched partials from the route.

router.match(req, res)

Match a route on a router.

handler = router.start()

Return a function that can be passed directly to Micro.

Installation

$ npm install micro-server-router

See Also

License

MIT