Middleware

Typed middleware contracts and the inline helper.

Type

type Middleware<TAdds = Record<never, never>, TNeeds = Record<never, never>>

TAdds is added to req.data; TNeeds is required from an earlier middleware. Annotate a constant, or use the helper for inline middleware.

Helper

function middleware<TAdds, TNeeds>(listener): Middleware<TAdds, TNeeds>

See the middleware guide for registration order, per-route arrays, and execution order.