Skip to content

lagden/koa-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-router

NPM version Node.js CI Coverage Status

The simple and tiny route middleware for koa.

Install

$ npm i @tadashi/koa-router

Usage

Contrived example:

import Koa from 'koa'
import router from '@tadashi/koa-router'

const fakeAuth = (ctx, next) => {
  ctx.state.auth = true
  return next()
}

const productMiddleware = ctx => {
  ctx.body = {
    auth: ctx.state.auth,
    id: ctx.params.id
  }
}

const app = new Koa()
app
  .use(router.get('/product/:id', fakeAuth, productMiddleware))
  .use(router.all('/', ctx => {
    ctx.body = 'nothing to see here!'
  }))

//...

Tip

It's possible to use koa-compose to group routes.
See an example in router.spec.js.


Important

Buy me a coffee!
BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4

License

MIT © Thiago Lagden

About

The simple and tiny route middleware for koa.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors