Skip to main content

Class: abstract Middleware<Options>

Since

1.0.0

Extends

  • Piece<Options, "middlewares">

Type parameters

Type parameterValue
Options extends OptionsOptions

Constructors

new Middleware()

new Middleware<Options>(context: LoaderContext, options: Options): Middleware<Options>

Parameters

ParameterType
contextLoaderContext
optionsOptions

Returns

Middleware<Options>

Overrides

Piece<Options, 'middlewares'>.constructor

Source

projects/plugins/packages/api/src/lib/structures/Middleware.ts:23

Properties

position

readonly position: number

The position the middleware has. The MiddlewareStore will run all middlewares with lower position than this one.

The built-in middlewares follow the following positions:

  • headers: 10
  • body: 20
  • cookies: 30
  • auth: 40

Source

projects/plugins/packages/api/src/lib/structures/Middleware.ts:21

Methods

run()

abstract run(request: ApiRequest, response: ApiResponse<IncomingMessage>, route: null | Route <RouteOptions>): unknown

The method to be overridden by other middlewares.

Parameters

ParameterTypeDescription
requestApiRequestThe client's request.
responseApiResponse<IncomingMessage>The server's response.
routenull | Route <RouteOptions>The route that matched this request, will be null if none matched.

Returns

unknown

Source

projects/plugins/packages/api/src/lib/structures/Middleware.ts:34