https://github.com/magicdawn/egg-compose
compose koa middleware to an egg.js action
https://github.com/magicdawn/egg-compose
Last synced: 3 months ago
JSON representation
compose koa middleware to an egg.js action
- Host: GitHub
- URL: https://github.com/magicdawn/egg-compose
- Owner: magicdawn
- License: mit
- Created: 2017-05-11T14:30:27.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-11T15:22:02.000Z (about 9 years ago)
- Last Synced: 2024-12-17T05:24:24.843Z (over 1 year ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-compose
> compose koa middleware to an egg.js action
[](https://travis-ci.org/magicdawn/egg-compose)
[](https://codecov.io/gh/magicdawn/egg-compose)
[](https://www.npmjs.com/package/egg-compose)
[](https://www.npmjs.com/package/egg-compose)
[](http://magicdawn.mit-license.org)
## Install
```sh
$ npm i egg-compose --save
```
## API
```js
const compose = require('egg-compose');
```
### action example
```js
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 包装一层即可使用
```js
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](CHANGELOG.md)
## License
the MIT License http://magicdawn.mit-license.org