Browse Source

docs(core): Add docs on middleware

Michael Bromley 4 years ago
parent
commit
994cc62478

+ 32 - 1
packages/core/src/common/types/common-types.ts

@@ -166,4 +166,35 @@ export type PriceCalculationResult = {
 // tslint:disable-next-line:ban-types
 export type MiddlewareHandler = Type<any> | Function;
 
-export type Middleware = { handler: MiddlewareHandler; route: string; beforeListen?: boolean };
+/**
+ * @description
+ * Defines API middleware, set in the {@link ApiOptions}. Middleware can be either
+ * [Express middleware](https://expressjs.com/en/guide/using-middleware.html) or [NestJS middleware](https://docs.nestjs.com/middleware).
+ *
+ * @docsCategory Common
+ */
+export interface Middleware {
+    /**
+     * @description
+     * The Express middleware function or NestJS `NestMiddleware` class.
+     */
+    handler: MiddlewareHandler;
+    /**
+     * @description
+     * 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.
+     */
+    route: string;
+    /**
+     * @description
+     * 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.
+     *
+     * @default false
+     */
+    beforeListen?: boolean;
+}

+ 0 - 1
packages/core/src/config/vendure-config.ts

@@ -163,7 +163,6 @@ export interface ApiOptions {
      *
      * @default []
      */
-    // tslint:disable-next-line:ban-types
     middleware?: Middleware[];
     /**
      * @description