beware
v0.0.4
Published
Lightweight async/await middleware library (formerly middlewerewolf)
Downloads
7
Maintainers
Readme
Beware
Lightweight async/await middleware library (formerly middlewerewolf)
Installation
yarn add beware
Usage
import Beware from "beware";
let app = new Beware();
// 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 beware
git clone [email protected]: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.