1.0.4 • Published 7 years ago

koa-router-interceptor v1.0.4

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

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

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago