middlewerewolf
v0.0.4
Published
Lightweight ES6 async/await middleware library
Downloads
9
Maintainers
Readme
middlewerewolf
Lightweight ES6 async/await middleware library
Installation
yarn add middlewerewolf
Usage
import middlewerewolf from "middlewerewolf";
let app = new middlewerewolf();
// This middleware will execute without issue
app.use(async (ctx, next) => {
ctx.foo = true;
await next();
});
// This middleware will execute, but does not call next()
app.use(async ctx => {
ctx.bar = true;
});
// This middleware will not execute, as the previous middleware
// did not call next()
app.use(async ctx => {
ctx.baz = true;
});
// Register multiple middleware with a single command
app.all([
async ctx => {
ctx.foo = true;
await next();
},
async ctx => {
ctx.bar = true;
await next();
}
]);
// Compose a new middleware execution chain
let fn = app.compose();
// Execute the chain
fn({
initial_context: true
}).then(ctx => {
console.log("All done here!");
}).catch(err => {
console.log("Handle errors like a boss.");
});
Build middlewerewolf
git clone [email protected]:aewing/middlewerewolf.git
cd middlewerewolf/
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.