Skip to content

covenix / Use

Function: Use()

Use(...middleware): ClassDecorator & MethodDecorator

Defined in: src/decorators.ts:334

Attaches Express middleware to run before the handler — auth beyond @Security, rate limiting, caching, logging, etc. Plain RequestHandlers, so the whole Express ecosystem composes.

Usable on a method or on the controller class (applies to every route). Class-level runs first, then method-level, in source order. In the full chain covenix builds, @Use runs after @Security and before multipart parsing (security → @Use → multipart → handler). Middleware that sends a response (or doesn't call next) short-circuits — the handler won't run.

Parameters

middleware

...RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]

One or more Express RequestHandlers.

Returns

ClassDecorator & MethodDecorator

Example

ts
@Route('admin')
@Use(rateLimit({ max: 100 }))   // every route in the controller
class AdminController {
  @Delete('{id}')
  @Use(auditLog())              // just this route
  remove() {}
}