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/...,求解?
PHP中文网2017-04-17 15:24:30
找到方法了
npm install koa-convert --save
從 'koa-convert' 匯入轉換
app.use(convert(require('koa-static')(__dirname + '/public')));
PHPz2017-04-17 15:24:30
看這裡!
是你仍然在用傳統的 1.x 裡的生成器語法才會出現這條提示,是 koa 善意的提醒啦,避免以後升到 v3 你的代碼就癱瘓了!所以如果你還是繼續想使用生成器語法的話就藉助 co 模組吧!
官方的栗子:
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:既然你都用 v2 了,為啥不 async
/ await
用起來呢!