Koa2 的安装运行记录(二)

本文介绍了一个基于Koa2的登录系统实现方案,利用koa-passport和passport-local进行Ajax登录与登出操作,并推荐了几种适用于Koa2的日志中间件,如concurrency-logger和koa-logger,帮助开发者更好地记录应用程序运行状态。

参考 :koa2-boilerplate    https://github.com/superalsrk/koa2-boilerplate

          Ajax Login and Ajax Logout in Koa2, based on koa-passport and passport-local

         https://github.com/koajs/koa/wiki   有中间件列表

 

1、rkusa/koa-passport    https://github.com/rkusa/koa-passport

 

 

二、Logging 中间件:

1)(推荐) concurrency-logger - logging requests concurrently and in context

              https://github.com/PabloSichert/concurrency-logger

 

2)、    koa-logger - development style logger    

安装:npm install koa-logger --save-dev
代码中增加:
var logger = require('koa-logger') app.use(logger())

 功能类似下列函数:

app.use(async (ctx, next) => {
   const start = new Date();
   await next();
   const ms = new Date() - start;
   console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});

 

3)(暂不考虑) koa-log4 - a wrapper for log4js-node which supports koa middleware

   

 

转载于:https://www.cnblogs.com/hopesun/p/6073682.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值