A middleware function: pre-process, call next(), post-process. May
short-circuit by returning a response without calling next().
Example 1
Example 1
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)); };
(ctx: IRequestContext,next: NextFunction) => void | HandlerResult | Promise<void | HandlerResult>