@waveorb/router
v0.1.1
Published
Waveorb router
Downloads
156
Readme
Waveorb Router
This library maps incoming HTTP requests to functions.
Install
npm i @waveorb/router
Usage
var router = require('@waveorb/router')
var routes = [
{
path: '/',
to: 'app/pages/home.js'
}
]
var r = router({ routes })
var route = r.match(req)
The route object on match contains:
{
path: '/',
to: 'app/pages/home.js',
pattern: /^\/$/,
matches: {},
result: [AsyncFunction (anonymous)]
}
Wildcard routes
The matches for wildcards exist in route.matches
.
For the route /articles/:name
with the req.pathname
of /article/hello
, we get:
{
path: '/article/:name',
to: 'app/pages/article.js',
pattern: /^\/article\/(.+?)$/,
matches: { name: 'hello' },
result: [AsyncFunction (anonymous)]
}
Created by Eldøy Projects