@nestjs/common#NestModule TypeScript Examples

The following examples show how to use @nestjs/common#NestModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.module.ts    From nest-js-quiz-manager with MIT License 6 votes vote down vote up
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    TypeOrmModule.forRootAsync(typeOrmAsyncConfig),
    EventEmitterModule.forRoot(),
    MulterModule.register({ dest: './uploads' }),
    QuizModule,
    UserModule,
    AuthModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(ApiTokenCheckMiddleware)
      .forRoutes({ path: '/', method: RequestMethod.ALL });
  }
}
Example #2
Source File: app.module.ts    From life-helper-backend with MIT License 6 votes vote down vote up
@Module({
  imports: [
    TypeOrmModule.forRoot(TypeOrmConfig),
    RedisModule.register(RedisConfig),
    ScheduleModule.forRoot(),
    SharedModule,
    AuthModule,
    UserModule,
    CalendarModule,
    IpModule,
    DiaryModule,
    UploadModule,
    SystemModule,
    WeatherModule,
  ],

  providers: [{ provide: APP_FILTER, useClass: AllExceptionFilter }],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): MiddlewareConsumer | void {
    /** 中间件列表 */
    const middlewares = [AuthMiddleware]

    consumer.apply(...middlewares).forRoutes({ path: '*', method: RequestMethod.ALL })
  }
}
Example #3
Source File: http-environment.module.ts    From nest-xray with MIT License 6 votes vote down vote up
// this module is global to ensure that middlewares are only called once
@Global()
@Module({ imports: [AsyncHooksModule] })
export class HttpEnvironmentModule implements NestModule {
  public configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(AsyncHooksMiddleware)
      .forRoutes("/")
      .apply(HttpTracingMiddleware)
      .forRoutes("/");
  }
}
Example #4
Source File: auth.module.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
@Module({
    exports: [AuthService],
    imports: [SystemModule],
    providers: [AuthService],
})
export class AuthModule implements OnModuleInit, NestModule {
    constructor(
        @Inject(HttpAdapterHost) private readonly httpAdapterHost: HttpAdapterHost,
        @Inject(AuthService) private readonly loader: AuthService,
    ) {}

    configure(consumer: MiddlewareConsumer) {
        consumer.apply(cookieParser()).forRoutes('*');

        consumer
            .apply(ApiTokenMiddleware, AuthTokenMiddleware)
            .exclude(
                {
                    path: '/graphql',
                    method: RequestMethod.GET,
                },
                {
                    path: '/api-docs',
                    method: RequestMethod.GET,
                },
            )
            .forRoutes('*');
    }

    onModuleInit(): void {
        if (!this.httpAdapterHost) {
            return;
        }

        const {httpAdapter} = this.httpAdapterHost;

        this.loader.register(httpAdapter);
    }
}
Example #5
Source File: auth.module.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Module({
	imports: [
		TypeOrmModule.forFeature([User, Tenant, Invite, PasswordReset, Role, RolePermission, UserRole, AuthenticationMethod]),
		SharedModule
	],
	controllers: [
		AuthController,
		AuthMethodController,
	],
	providers: [
		PasswordResetService,

		...Strategies
	],
})
export class AuthModule implements NestModule {
	configure(consumer: MiddlewareConsumer) {
	  	consumer
			.apply(LocalStrategyProvider)
			.forRoutes('/auth/login/local')
			.apply(DynamicStrategyProvider)
			.forRoutes('/auth/login/*');
	}
}
Example #6
Source File: app.module.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
@Module({
  imports: [
    ApiConfigModule,
    AuthModule,
    ConfigModule.forRoot({
      isGlobal: true,
      validationSchema: joi.object({
        ALLOW_BLOCK_MINED_POINTS: joi.boolean().default(false),
        API_URL: joi.string().required(),
        BLOCK_EXPLORER_URL: joi.string().required(),
        CHECK_EVENT_OCCURRED_AT: joi.boolean().default(true),
        CHECK_USER_CREATED_AT: joi.boolean().default(true),
        DATABASE_CONNECTION_POOL_URL: joi.string().required(),
        DATABASE_URL: joi.string().required(),
        DATADOG_URL: joi.string().required(),
        DISABLE_FAUCET: joi.boolean().default(false),
        DISABLE_LOGIN: joi.boolean().default(false),
        INCENTIVIZED_TESTNET_URL: joi.string().required(),
        INFLUXDB_API_TOKEN: joi.string().required(),
        INFLUXDB_BUCKET: joi.string().required(),
        INFLUXDB_URL: joi.string().required(),
        IRONFISH_API_KEY: joi.string().required(),
        MAGIC_SECRET_KEY: joi.string().required(),
        NETWORK_VERSION: joi.number().required(),
        NODE_UPTIME_ENABLED: joi.boolean().default(true),
        NODE_ENV: joi.string().required(),
        PORT: joi.number().default(8003),
      }),
    }),
    DatadogModule,
    LoggerModule,
    ...JOBS_MODULES,
    ...REST_MODULES,
  ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): void {
    consumer
      .apply(RequireSslMiddleware, ContextMiddleware)
      .forRoutes({ path: '*', method: RequestMethod.ALL });
  }
}
Example #7
Source File: index.ts    From bank-server with MIT License 5 votes vote down vote up
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    AuthModule,
    UserModule,
    CurrencyModule,
    BillModule,
    TransactionModule,
    LanguageModule,
    MessageModule,
    NotificationModule,
    ScheduleModule.forRoot(),
    TypeOrmModule.forRootAsync({
      imports: [SharedModule],
      useFactory: (configService: ConfigService) => ({
        type: 'postgres',
        host: configService.get('DB_HOST'),
        port: +configService.get<number>('DB_PORT'),
        username: configService.get('DB_USERNAME'),
        password: configService.get('DB_PASSWORD'),
        database: configService.get('DB_DATABASE'),
        entities: [__dirname + '/../../modules/**/*.entity{.ts,.js}'],
        migrations: [__dirname + '/../../migrations/*{.ts,.js}'],
        namingStrategy: new SnakeNamingStrategy(),
        synchronize: false,
        subscribers: [
          UserSubscriber,
          UserAuthSubscriber,
          UserAuthForgottenPasswordSubscriber,
        ],
        migrationsRun: true,
        logging: true,
      }),
      inject: [ConfigService],
    }),
    MailerModule.forRootAsync({
      useFactory: (configService: ConfigService) => ({
        transport: {
          host: configService.get('EMAIL_HOST'),
          port: +configService.get('EMAIL_PORT'),
          secure: true,
          auth: {
            user: configService.get('EMAIL_ADDRESS'),
            pass: configService.get('EMAIL_PASSWORD'),
          },
          tls: {
            rejectUnauthorized: false,
          },
        },
        defaults: {
          from: '"Bank Application" <[email protected]>',
        },
        template: {
          dir: process.cwd() + 'src/modules/transaction/templates/',
          adapter: new HandlebarsAdapter(),
          options: { strict: true },
        },
      }),
      inject: [ConfigService],
    }),
  ],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): MiddlewareConsumer | void {
    consumer.apply(contextMiddleware).forRoutes('*');
  }
}