koa中间件

function pv(ctx){
    global.console.log(ctx.path);
}
module.exports=function(){
  return async function(ctx,next){
        pv(ctx);
        await next();    //next是继续执行下面的中间件,如果不写会直接跳出,不会继续执行
  }  
}
//app.js
const pv = require('./middleware/koa-pv');
app.use(pv())

猜你喜欢

转载自www.cnblogs.com/lanshu123/p/10703866.html