@nestjs/common#HttpModule TypeScript Examples

The following examples show how to use @nestjs/common#HttpModule. 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: auth.module.ts    From 42_checkIn with GNU General Public License v3.0 6 votes vote down vote up
@Module({
  imports: [
    HttpModule,
    PassportModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        secret: configService.get('jwt.secret'),
        signOptions: { expiresIn: '7d' },
      }),
    }),
    LoggerModule,
  ],
  providers: [AuthService, JwtStrategy, FtStrategy],
  exports: [AuthService],
})
export class AuthModule {}
Example #2
Source File: user.module.ts    From 42_checkIn with GNU General Public License v3.0 6 votes vote down vote up
@Module({
  imports: [
    AuthModule,
    TypeOrmModule.forFeature([UserRepository]),
    forwardRef(() => CardModule),
    forwardRef(() => LogModule),
    LoggerModule,
    HttpModule,
    ConfigModule,
    forwardRef(() => WaitingModule),
  ],
  controllers: [UserController],
  providers: [UserService],
  exports: [TypeOrmModule, UserService],
})
export class UserModule {}
Example #3
Source File: services.module.ts    From barista with Apache License 2.0 6 votes vote down vote up
services = [
  BomLicenseExceptionService,
  BomManualLicenseService,
  BomSecurityExceptionService,
  ClearlyDefinedService,
  DeploymentTypeService,
  GlobalSearchService,
  HttpModule,
  JwtStrategy,
  LdapService,
  LicenseScanResultItemService,
  LicenseScanResultService,
  LicenseService,
  LicenseStatusDeploymentTypeService,
  LoggerService,
  LocalStrategy,
  ObligationService,
  ObligationTypeService,
  OutputFormatTypeService,
  PackageManagerService,
  ProjectAttributionService,
  ProjectDevelopmentTypeService,
  ProjectNotesService,
  ProjectScanStatusTypeService,
  ProjectService,
  ProjectStatusTypeService,
  ScanLogService,
  ScanService,
  SecurityScanResultItemService,
  SecurityScanResultItemStatusTypeService,
  SecurityScanResultService,
  SystemConfigurationService,
  ToolTipService,
  UserService,
  VulnerabilityStatusDeploymentTypeService,
]
Example #4
Source File: index.ts    From bank-server with MIT License 6 votes vote down vote up
@Module({
  imports: [
    HttpModule,
    forwardRef(() => UserModule),
    forwardRef(() => TransactionModule),
    forwardRef(() => BillModule),
    TypeOrmModule.forFeature([CurrencyRepository]),
  ],
  controllers: [CurrencyController],
  exports: [CurrencyService, CurrencyCron],
  providers: [CurrencyService, CurrencyCron],
})
export class CurrencyModule {}
Example #5
Source File: app.module.ts    From MyAPI with MIT License 6 votes vote down vote up
@Module({
  imports: [
    HttpModule,
    AuthModule,
    UserModule,
    RoleModule,
    DocumentTypeModule
  ],
  controllers: [
    AppController,
    AuthController,
    UserController,
    RoleController,
    DocumentTypeController
  ],
  providers: [Logger, AppService],
})
export class AppModule {}
Example #6
Source File: release-notes.module.ts    From office-hours with GNU General Public License v3.0 6 votes vote down vote up
@Module({
  controllers: [ReleaseNotesController],
  providers: [],
  imports: [
    HttpModule.registerAsync({
      useFactory: () => ({
        timeout: 5000,
        maxRedirects: 5,
      }),
    }),
  ],
})
export class ReleaseNotesModule {}
Example #7
Source File: app.module.ts    From 42_checkIn with GNU General Public License v3.0 5 votes vote down vote up
@Module({
  imports: [
    ConfigModule.forRoot({
      load: [configuration],
      isGlobal: true,
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('database.host'),
        port: configService.get('database.port'),
        username: configService.get('database.username'),
        password: configService.get('database.password'),
        database: configService.get('database.name'),
        entities: [join(__dirname, '/**/*.entity.js')],
        synchronize: true,
      }),
    }),
    // ServeStaticModule.forRoot({
    //   rootPath: resolve(__dirname, '../../../client/build'),
    // }),
    TerminusModule,
    UserModule,
    AuthModule,
    CardModule,
    LogModule,
    HealthModule,
    LoggerModule,
    ThrottlerModule.forRoot({
      ttl: 60,
      limit: 20,
    }),
    WaitingModule,
    HttpModule,
    // MailerModule.forRootAsync({
    //   imports: [ConfigModule],
    //   inject: [ConfigService],
    //   useFactory: (configService: ConfigService) => ({
    //     transport: configService.get('mailer.mail'),
    //     defaults: {
    //       from: '"42 출입 시스템" <[email protected]>',
    //     },
    //     template: {
    //       dir: __dirname + '/templates',
    //       adapter: new EjsAdapter(),
    //       options: {
    //         strict: true,
    //       },
    //     },
    //   }),
    // }),
    ScheduleModule.forRoot(),
  ],
  controllers: [AppController, HealthController, WaitingController],
  providers: [
    AppService,
    Logger,
    { provide: APP_GUARD, useClass: TokenThrottlerGuard },
  ],
})
export class AppModule {}
Example #8
Source File: resources.module.ts    From office-hours with GNU General Public License v3.0 5 votes vote down vote up
@Module({
  controllers: [ResourcesController],
  providers: [ResourcesService],
  imports: [
    HttpModule.registerAsync({
      useFactory: () => ({
        timeout: 5000,
        maxRedirects: 5,
      }),
    }),
  ],
})
export class ResourcesModule {}
Example #9
Source File: google-recaptcha-async-module.spec.ts    From google-recaptcha with MIT License 4 votes vote down vote up
describe('Google recaptcha async module', () => {
    const checkDefaultConfigs = (defaults: AxiosRequestConfig) => {
        expect(defaults).toBeDefined();
        expect(defaults.proxy).toBeDefined();

        const proxy: AxiosProxyConfig = defaults.proxy as AxiosProxyConfig;

        expect(proxy).toBeDefined();
        expect(typeof proxy).toBe('object');
        expect(proxy.host).toBe('TEST_PROXY_HOST');
        expect(proxy.port).toBe(7777);
    };

    test('Test via import module and use default axios config',  async () => {
        const testingModule = await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    imports: [
                        HttpModule.register({
                            proxy: {
                                host: 'TEST_PROXY_HOST',
                                port: 7777,
                            },
                            data: 'TEST',
                            timeout: 1000000000,
                        }),
                        TestConfigModule,
                    ],
                    useFactory: (config: TestConfigService, http: HttpService) => ({
                        ...config.getGoogleRecaptchaOptions(),
                        axiosConfig: http.axiosRef.defaults,
                    }),
                    inject: [
                        TestConfigService,
                        HttpService,
                    ],
                }),
            ],
        }).compile();

        const app = testingModule.createNestApplication();

        await app.init();

        const validator = app.get(GoogleRecaptchaValidator);
        expect(validator).toBeInstanceOf(GoogleRecaptchaValidator);

        const axiosInstance: AxiosInstance = app.get(RECAPTCHA_AXIOS_INSTANCE);

        checkDefaultConfigs(axiosInstance.defaults);

        expect(axiosInstance.defaults.data).toBeUndefined();

        const options: GoogleRecaptchaModuleOptions = app.get(RECAPTCHA_OPTIONS);

        expect(options).toBeDefined();

        checkDefaultConfigs(options.axiosConfig);

        expect(options.axiosConfig.data).toBe('TEST');
    });

    test('Test via useClass',  async () => {
        const testingModule = await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    useClass: GoogleRecaptchaModuleOptionsFactory,
                }),
            ],
        }).compile();

        const app = testingModule.createNestApplication();

        const validator = app.get(GoogleRecaptchaValidator);
        expect(validator).toBeInstanceOf(GoogleRecaptchaValidator);
    });

    test('Test via useExisting',  async () => {
        const testingModule = await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    imports: [
                        TestConfigModule,
                    ],
                    useExisting: GoogleRecaptchaModuleOptionsFactory,
                }),
            ],
        }).compile();

        const app = testingModule.createNestApplication();

        const validator = app.get(GoogleRecaptchaValidator);
        expect(validator).toBeInstanceOf(GoogleRecaptchaValidator);
    });

    test('Test via useClass that not implement GoogleRecaptchaOptionsFactory',  async () => {
        await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRootAsync({
                    useClass: TestConfigModule as any,
                }),
            ],
        }).compile()
            .then(() => expect(true).toBeFalsy())
            .catch(e => expect(e.message).toBe('Factory must be implement \'GoogleRecaptchaOptionsFactory\' interface.'));
    });
});