Defines API middleware, set in the ApiOptions. Middleware can be either Express middleware or NestJS middleware.
Internally, Vendure relies on Express's built-in JSON parser (express.json(), which itself wraps
the body-parser library) to parse incoming JSON data. By default, the maximum body size is set to
100kb. Attempting to send a request with more than 100kb of JSON data will result in a
PayloadTooLargeError. To increase this limit, we can manually configure the middleware:
Example
The route may also be scoped to a single API path if you only want to raise the limit (or
otherwise customize body parsing) for that route, leaving the default parser in place everywhere
else:
Example
MiddlewareHandlerThe Express middleware function or NestJS NestMiddleware class.
stringThe 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.
booleanv1.1.0falseWhen 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
JSON body-parsing middleware which is automatically applied by Express. This can be useful in certain cases such as when you need to access the
raw unparsed request for a specific route.