search

Home  >  Q&A  >  body text

node.js - koa-static出现generators will been removed in v3?

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

怪我咯怪我咯2785 days ago695

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:24:30

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

    import convert from 'koa-convert'

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

    reply
    0
  • PHPz

    PHPz2017-04-17 15:24:30

    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!

    reply
    0
  • Cancelreply