node.js - koa-static出现generators will been removed in v3?
怪我咯2017-04-17 15:22:30
0
2
710
koa deprecated Support for generators will been removed in v3. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/...,求解?
This prompt appears because you are still using the traditional generator syntax in 1. So if you still want to use generator syntax, just use the co module!
Official chestnut:
app.use(co.wrap(function *(ctx, next) {
const start = new Date();
yield next();
const ms = new Date() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
}));
PS: Since you are already using v2, why not async / await use it!
找到方法了
npm install koa-convert --save
import convert from 'koa-convert'
app.use(convert(require('koa-static')(__dirname + '/public')));
Look here!
This prompt appears because you are still using the traditional generator syntax in 1. So if you still want to use generator syntax, just use the co module!
Official chestnut:
PS: Since you are already using v2, why not
async
/await
use it!