美文网首页
自定义中间件

自定义中间件

作者: Wrestle_Mania | 来源:发表于2019-12-10 13:12 被阅读0次
    • middleware/koa-pv.js
    const pv = ctx => {
      console.log("path:" + ctx.path);
    };
    
    module.exports = () => async (ctx, next) => {
      pv(ctx);
      await next();
    };
    
    • app.js
    const Koa = require("koa");
    const pv = require("./middleware/koa-pv");
    app.use(pv());
    

    相关文章

      网友评论

          本文标题:自定义中间件

          本文链接:https://www.haomeiwen.com/subject/kwxggctx.html