Skip to content

slashhuang/koa-router-interceptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-router-interceptor

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

About

A interceptor middleware for koa-router

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published