koa-router-interceptor

1.0.4 • Public • Published

koa-router-interceptor

when using koa-router@next ,only regular expression is not enough

to handle dynamic router situation。

this koa-router-interceptor module is to make koa-router more flexible

interceptor should return a true value to handle koa-router logic.

if boolean==true is not returned or resolved, koa-router-interceptor automatically

call next koa middleware for you

install

    npm install koa-router-interceptor

soure code

koa-router-interceptor

usage case

 
    const http = require('http');
    const Koa = require('koa');
    const app = new Koa();
    const KoaRouter = require('koa-router')();
    const KoaRouterInterceptor = require('koa-router-interceptor');
    KoaRouter.get('/hello',(ctx,next)=>{
        ctx.body="hello world"
    })
    app.use(KoaRouterInterceptor(KoaRouter,(ctx,next)=>{
       return !(ctx.path.substr(0,4)=='/api' || /\./.test(ctx.path));
    }));
    http.createServer(app.callback()).listen(7000)
 

changelog

v1.0.4 ==> simplify logic with Promise

notice

it is strongly recommended to use node >=6.0

Package Sidebar

Install

npm i koa-router-interceptor

Weekly Downloads

5

Version

1.0.4

License

ISC

Last publish

Collaborators

  • slashhuang