|
|
@@ -1,4 +1,11 @@
|
|
|
-import { MiddlewareConsumer, Module, NestModule, OnApplicationShutdown } from '@nestjs/common';
|
|
|
+import {
|
|
|
+ MiddlewareConsumer,
|
|
|
+ Module,
|
|
|
+ NestMiddleware,
|
|
|
+ NestModule,
|
|
|
+ OnApplicationShutdown,
|
|
|
+} from '@nestjs/common';
|
|
|
+import { Type } from '@vendure/common/lib/shared-types';
|
|
|
import { RequestHandler } from 'express';
|
|
|
|
|
|
import { ApiModule } from './api/api.module';
|
|
|
@@ -10,6 +17,9 @@ import { I18nModule } from './i18n/i18n.module';
|
|
|
import { I18nService } from './i18n/i18n.service';
|
|
|
import { PluginModule } from './plugin/plugin.module';
|
|
|
|
|
|
+// tslint:disable-next-line:ban-types
|
|
|
+type Middleware = Type<any> | Function;
|
|
|
+
|
|
|
@Module({
|
|
|
imports: [ConfigModule, I18nModule, ApiModule, PluginModule.forRoot(), HealthCheckModule],
|
|
|
})
|
|
|
@@ -19,7 +29,7 @@ export class AppModule implements NestModule, OnApplicationShutdown {
|
|
|
configure(consumer: MiddlewareConsumer) {
|
|
|
const { adminApiPath, shopApiPath, middleware } = this.configService.apiOptions;
|
|
|
const i18nextHandler = this.i18nService.handle();
|
|
|
- const defaultMiddleware: Array<{ handler: RequestHandler; route?: string }> = [
|
|
|
+ const defaultMiddleware: Array<{ handler: Middleware; route?: string }> = [
|
|
|
{ handler: i18nextHandler, route: adminApiPath },
|
|
|
{ handler: i18nextHandler, route: shopApiPath },
|
|
|
];
|
|
|
@@ -40,9 +50,9 @@ export class AppModule implements NestModule, OnApplicationShutdown {
|
|
|
* Groups middleware handlers together in an object with the route as the key.
|
|
|
*/
|
|
|
private groupMiddlewareByRoute(
|
|
|
- middlewareArray: Array<{ handler: RequestHandler; route?: string }>,
|
|
|
- ): { [route: string]: RequestHandler[] } {
|
|
|
- const result = {} as { [route: string]: RequestHandler[] };
|
|
|
+ middlewareArray: Array<{ handler: Middleware; route?: string }>,
|
|
|
+ ): { [route: string]: Middleware[] } {
|
|
|
+ const result = {} as { [route: string]: Middleware[] };
|
|
|
for (const middleware of middlewareArray) {
|
|
|
const route = middleware.route || this.configService.apiOptions.adminApiPath;
|
|
|
if (!result[route]) {
|