const timing: MiddlewareFunction = async (ctx, next) => {
const runtime = ctx.services.get<IRuntimeServices>(CAPABILITIES.RUNTIME);
await next();
// ctx.startTime is a monotonic runtime.hrtime() reading; subtract it from
// another monotonic reading — never from a wall-clock epoch.
ctx.response.header('X-Duration', String(runtime.hrtime() - ctx.startTime));
};
A middleware function: pre-process, call
next(), post-process. May short-circuit by returning a response without callingnext().