titbit v22.2.1 已经发布,Node.js 环境的 Web 后端框架

titbit v22.2.1 已经发布,Node.js 环境的 Web 后端框架

此版本更新内容包括:

  • 加载中间件支持传递对象,只要对象包括mid或middleware属性。

要求mid是一个普通函数,运行此函数要返回一个真正的中间件函数。

middleware则应该是一个完整的中间件函数,会自动进行this绑定(箭头函数无法绑定this)。

会先检测mid属性,不满足条件才会检测middleware,但是如果mid的返回值不满足条件会抛出错误。


class midt {
  constructor () {
    this.name = 'test-midt'
  }

  mid () {
    let self = this
    return async (c, next) => {
      console.log(self.name)
      await next()
    }
  }

}

class midware {
  constructor () {
    this.name = 'test-midware'
  }

  async middleware (c, next) {
    console.log(this.name)
    await next()
  }

}

const app = new titbit()

app.use( new midt )
  .use(new midware)

app.run(1234)

详情查看:https://gitee.com/daoio/titbit/releases/v22.2.1

猜你喜欢

转载自blog.csdn.net/weixin_40193113/article/details/113788102