0.0.2 • Published 8 years ago

egg-compose v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

egg-compose

compose koa middleware to an egg.js action

Build Status Coverage Status npm version npm downloads npm license

Install

$ npm i egg-compose --save

API

const compose = require('egg-compose');

action example

const compose = require('egg-compose')

module.exports = app => {
  class HomeController extends app.Controller {}

  Object.assign(HomeController.prototype, {
    hello: compose([
      async(ctx, next) => {
        ctx.body = 'hello'
        return next()
      },
      async(ctx, next) => {
        ctx.body += ' world'
      },
    ])
  })

  return HomeController
}

the home.hello will results hello world text

co-wechat example

https://github.com/node-webot/co-wechat#middleware-方法变更

使用 compose 包装一层即可使用

const compose = require('egg-compose')
const wechat = require('co-wechat')

module.exports = app => {
  class HomeController extends app.Controller {}

  Object.assign(HomeController.prototype, {
    wechat: compose([
      wechat(config).middleware(async message => {
        // blabla
      })
    ])
  })

  return HomeController
}

Changelog

CHANGELOG.md

License

the MIT License http://magicdawn.mit-license.org