mwa
Easily create your own middleware layer.
Last updated 2 months ago by zce .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mwa 
SYNC missed versions from official npm registry.

mwa

GitHub Actions Status Travis CI Status Coverage Status License NPM Downloads NPM Version Dependency Status devDependency Status Code Style

Middle Ware Async, Easily create your own middleware layer. It's like koa's middleware.

Installation

$ npm install mwa

# or yarn
$ yarn add mwa

Usage

const app = mwa()

app.use(async (state, next) => {
  console.log('mw1 start: ', state)
  state.a = 1
  await next()
  console.log('mw1 end: ', state)
})

app.use(async (state, next) => {
  console.log('mw2 start: ', state)
  state.b = 1
  await next()
  console.log('mw2 end: ', state)
})

;(async () => {
  const initialState = {}
  await app.run(initialState)
  console.log('all completed')
})()

API

mwa()

Return a new Mwa instance.

Instance

.use(middleware)

Use the given middleware. Return the instance itself.

middleware
  • Type: async function or async function[]
  • Details: middleware function.

.run(state)

Run all middlewares. Return a Promise.

state
  • Type: any
  • Details: middleware context.

Contributing

  1. Fork it on GitHub!
  2. Clone the fork to your own machine.
  3. Checkout your feature branch: git checkout -b my-awesome-feature
  4. Commit your changes to your own branch: git commit -am 'Add some feature'
  5. Push your work back up to your fork: git push -u origin my-awesome-feature
  6. Submit a Pull Request so that we can review your changes.

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

License

MIT © zce

Current Tags

  • 0.1.0                                ...           latest (2 months ago)

2 Versions

  • 0.1.0                                ...           2 months ago
  • 0.0.0                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |