koa-interceptors
An interceptors middleware for koa2
Introduction:
The interceptor automatically associates the router with the controller.
Usage
app.js
'use strict'; // modulesconst koa = ;const convert = ;const session = ;const Interceptors = ; // appconst app = ;// interceptorsconst interceptors = ; // use sessioninterceptors; // load routesapp;
/routers/home/login.js
'use strict'; moduleexports = '/login': action: 'login' // page action method: 'post' // if get can be omitted action: 'validate-login' // page action ;
/controllers/home/login.js
'use strict'; moduleexports = { // page action logic } { // page action logic };
Install
$ npm install koa-interceptors --save
API
Interceptors([routers, controllers, options])
routers
: the routers base dir.controllers
: the controllers base dir.options
: the koa-router options.
koa-router
Others see:Notice
The interceptor will add a property routeData
on koa ctx.