In Express you reach for req.locale = ... inside a middleware and hope the
downstream handler remembers what type it is. KickJS gives you a better home
for that data: a context decorator . You declare the key once, write a
typed resolve(ctx) function, register it at the scope it belongs to, and
every handler in that scope can call ctx.get('locale') with full type
safety. Anything you'd hang off req β request id, locale, the audit actor,
feature flags, an idempotency key β should live here instead. This article
is the field guide: the two factories, the full options surface, the five
registration scopes and how they fight, how to read values back from
handlers and services, the boot-time errors you should know on sight, and
three patterns worth stealing.
The two factories
KickJS ships two factories, and the difference is whether your resolver
needs to see the HTTP request.
defineHttpContextDecorator is for HTTP routes.β¦