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/...,求解?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
Ty80

找到方法了
npm install koa-convert --save

import convert from 'koa-convert'

app.use(convert(require('koa-static')(__dirname + '/public')));

PHPzhong

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:

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!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template