Beware
Lightweight async/await middleware library (formerly middlewerewolf)
Installation
yarn add beware
Usage
import Beware from "beware";
let app = new Beware();
app.use(async (ctx, next) => {
ctx.foo = true;
await next();
});
app.use(async ctx => {
ctx.bar = true;
});
app.use(async ctx => {
ctx.baz = true;
});
app.all([
async ctx => {
ctx.foo = true;
await next();
},
async ctx => {
ctx.bar = true;
await next();
}
]);
let fn = app.compose();
fn({
initial_context: true
}).then(ctx => {
console.log("All done here!");
}).catch(err => {
console.log("Handle errors like a boss.");
});
Build beware
git clone git@github.com:aewing/beware.git
cd beware/
make lint
make flow
make test
make build
Contributing
Pull requests are welcome, but I intend to keep this package as lightweight and future compliant as possible.
Credits
Much love to koa-compose, which inspired this package.