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/tree/v2.x#old-signature-middleware-v1x---deprecated,求解?
擁有18年軟件開發(fā)和IT教學(xué)經(jīng)驗(yàn)。曾任多家上市公司技術(shù)總監(jiān)、架構(gòu)師、項(xiàng)目經(jīng)理、高級(jí)軟件工程師等職務(wù)。 網(wǎng)絡(luò)人氣名人講師,...
是你仍然在用傳統(tǒng)的 1.x 里的生成器語(yǔ)法才會(huì)出現(xiàn)這條提示,是 koa 善意的提醒啦,避免以后升到 v3 你的代碼就癱瘓了!所以如果你仍然繼續(xù)想使用生成器語(yǔ)法的話就借助 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 用起來呢!
找到方法了 npm install koa-convert --save
import convert from 'koa-convert'
app.use(convert(require('koa-static')(__dirname + '/public')));