hooks
hooks copied to clipboard
Combining multiple middleware with compose
This part is not documented on @feathersjs/hooks: https://github.com/koajs/koa/blob/master/docs/guide.md#combining-multiple-middleware-with-koa-compose
const { hooks, compose } = require('@feathersjs/hooks');
hooks(Hello, {
sayHi: [
compose([
logRuntime,
validateName,
compose([
/* ... */
])
])
]
});
Try it: https://runkit.com/embed/l7srsn9s0s2q
It can also be useful to call a chain of hooks inside a hook:
hooks(Hello, {
sayHi: [
async (ctx, next) => {
// ... stuff
await compose([
logRuntime,
validateName,
compose([
/* ... */
])
])(ctx);
// ... other stuff
await next();
}
]
});