app.module.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Module, MiddlewareConsumer, RequestMethod } from '@nestjs/common';
  2. import { APP_INTERCEPTOR } from '@nestjs/core';
  3. import { ServeStaticModule } from '@nestjs/serve-static';
  4. import { AppController } from './app.controller';
  5. import { AppService } from './app.service';
  6. import { ErrorInterceptor, TransformResInterceptor } from './interceptors';
  7. import { MilvusModule } from './milvus/milvus.module';
  8. import { CollectionsModule } from './collections/collections.module';
  9. import { UsersService } from './users/users.service';
  10. import { UsersModule } from './users/users.module';
  11. import { AuthModule } from './auth/auth.module';
  12. import { join } from 'path';
  13. import { PartitionsModule } from './partitions/partitions.module';
  14. import { SchemaModule } from './schema/schema.module';
  15. import { LoggerMiddleware } from './middlewares/logger';
  16. @Module({
  17. imports: [
  18. ServeStaticModule.forRoot({
  19. rootPath: join(__dirname, '..', 'build'),
  20. // renderPath: '/', // only root render static html
  21. }),
  22. MilvusModule,
  23. CollectionsModule,
  24. UsersModule,
  25. AuthModule,
  26. PartitionsModule,
  27. SchemaModule,
  28. ],
  29. controllers: [AppController],
  30. providers: [
  31. AppService,
  32. // global interceptors
  33. {
  34. provide: APP_INTERCEPTOR,
  35. useClass: ErrorInterceptor,
  36. },
  37. {
  38. provide: APP_INTERCEPTOR,
  39. useClass: TransformResInterceptor,
  40. },
  41. UsersService,
  42. ],
  43. })
  44. export class AppModule {
  45. configure(consumer: MiddlewareConsumer) {
  46. consumer
  47. .apply(LoggerMiddleware)
  48. .forRoutes({ path: '*', method: RequestMethod.ALL });
  49. }
  50. }