AroundHooks to compose (applied in priority order)
Single composed AroundHook
const timing = (ctx, next) => {
const start = Date.now();
return next().finally(() => {
console.log(`Duration: ${Date.now() - start}ms`);
});
};
const auth = (ctx, next) => {
ctx.request.headers.Authorization = `Bearer ${getToken()}`;
return next();
};
const composed = composeAround(timing, auth);
Compose multiple around hooks into one using the "onion" model.
Each hook wraps the next, forming a chain where:
next(innermost)Execution order (example with 3 hooks):