class-validator#useContainer TypeScript Examples

The following examples show how to use class-validator#useContainer. 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: main.ts    From aqualink-app with MIT License 6 votes vote down vote up
async function bootstrap() {
  if (Object.values(serviceAccount).every((value) => !!value)) {
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
    });
  } else {
    Logger.warn('Firebase environments not provided', 'MAIN');
  }

  const app = await NestFactory.create(AppModule);

  const { config, documentOptions, customOptions } =
    configService.getSwaggerConfig();
  const document = SwaggerModule.createDocument(app, config, documentOptions);
  SwaggerModule.setup('api/docs', app, document, customOptions);

  app.enableCors();
  app.setGlobalPrefix('api');
  app.useGlobalPipes(
    new GlobalValidationPipe({ transform: true, skipTransformIds: ['appId'] }),
  );
  app.useGlobalFilters(
    new HttpExceptionFilter(),
    new UnauthorizedExceptionFilter(),
  );
  app.use(apiLoggerMiddleware);
  // eslint-disable-next-line react-hooks/rules-of-hooks
  useContainer(app.select(AppModule), { fallbackOnErrors: true });
  await app.listen(8080);
  // eslint-disable-next-line no-console
  console.log(`App listening on port 8080`);
}
Example #2
Source File: index.ts    From test with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
bootstrap = async () => {
  const app = await NestFactory.createMicroservice(ServiceModule, serverOptions)

  useContainer(app.select(ServiceModule), {
    fallback: true,
    fallbackOnErrors: true,
  })

  await app.listenAsync()

  if (module.hot) {
    module.hot.accept()
    module.hot.dispose(() => app.close())
  }
}