0.1.1 • Published 10 months ago

@waveorb/router v0.1.1

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

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

0.1.1

10 months ago

0.1.0

10 months ago