koa-route-dispatcher
Uber simple route middleware for koa. (koa-route)
support JSON format
const dispatcher = ;const routesMap = ; //map.jsapp;
Syntax
;
If you need a full-featured solution check out koa-router, a Koa clone of express-resource.
Installation
$ npm install koa-route-dispatcher
Example
// app.jsconst Koa = ;const app = ;const dispatcher = ;const routesMap = ; app;app; console;
// reoutes/map.json "path": "/pets" "method": "get" "controller": "pets.list" "opts": {} "path": "/pets/:name" "method": "get" "controller": "pets.show" "path": "/async/pets" "method": "get" "controller": "/async/pets.list" "opts": {} "path": "/async/pets/:name" "method": "get" "controller": "/async/pets.show" "opts": {}
// controllers/async/pets.js { return { ; };} moduleexports = list: async { const db = await ; const names = Object; ctxbody = 'pets: ' + names; } { const ctx = this; const db = ; const pet = dbname; if !pet return ctx; ctxbody = petname + ' is a ' + petspecies; };
License
MIT