main.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { NestFactory } from '@nestjs/core';
  2. import { AppModule } from './app.module';
  3. import { ValidationPipe } from '@nestjs/common';
  4. import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
  5. async function bootstrap() {
  6. const app = await NestFactory.create(AppModule);
  7. app.useGlobalPipes(new ValidationPipe());
  8. app.enableCors({
  9. origin: true, // Allow all origins
  10. methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
  11. credentials: true,
  12. });
  13. app.setGlobalPrefix('api'); // Set a global API prefix
  14. // Swagger / OpenAPI documentation
  15. const config = new DocumentBuilder()
  16. .setTitle('AuraK API')
  17. .setDescription('External API for accessing AuraK functionalities via API Key')
  18. .setVersion('1.0')
  19. .addApiKey({ type: 'apiKey', name: 'x-api-key', in: 'header' }, 'x-api-key')
  20. .build();
  21. const document = SwaggerModule.createDocument(app, config);
  22. SwaggerModule.setup('api/docs', app, document);
  23. await app.listen(process.env.PORT ?? 3001);
  24. // Ensure "Default" tenant exists
  25. const { TenantService } = await import('./tenant/tenant.service');
  26. const tenantService = app.get(TenantService);
  27. await tenantService.ensureDefaultTenant();
  28. }
  29. bootstrap();