🚨 Announcing Vendure v2 Beta

Middleware

Middleware

Defines API middleware, set in the ApiOptions. Middleware can be either Express middleware or NestJS middleware.

Signature

interface Middleware {
  handler: MiddlewareHandler;
  route: string;
  beforeListen?: boolean;
}

Members

handler

property
type:
MiddlewareHandler
The Express middleware function or NestJS NestMiddleware class.

route

property
type:
string

The route to which this middleware will apply. Pattern based routes are supported as well.

The 'ab*cd' route path will match abcd, ab_cd, abecd, and so on. The characters ?, +, *, and () may be used in a route path, and are subsets of their regular expression counterparts. The hyphen (-) and the dot (.) are interpreted literally.

beforeListen

property
v1.1.0
type:
boolean
default:
false
When set to true, this will cause the middleware to be applied before the Vendure server (and underlying Express server) starts listening for connections. In practical terms this means that the middleware will be at the very start of the middleware stack, before even the body-parser middleware which is automatically applied by NestJS. This can be useful in certain cases such as when you need to access the raw unparsed request for a specific route.