06112602ec
Version the NestJS TDLib gateway with Docker deployment, migrations, automated tests and platform integration documentation while excluding all account sessions, credentials, runtime databases and backups.
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { AppModule } from './app.module';
|
|
import { AllExceptionsFilter } from './common/filters/all-exceptions.filter';
|
|
import { ResponseInterceptor } from './common/interceptors/response.interceptor';
|
|
import { RequestIdInterceptor } from './common/interceptors/request-id.interceptor';
|
|
import { ValidationPipe } from './common/pipes/validation.pipe';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
import { Logger } from '@nestjs/common';
|
|
import helmet from 'helmet';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
const logger = new Logger('Bootstrap');
|
|
|
|
app.use(helmet());
|
|
const configuredOrigins = process.env.CORS_ORIGINS
|
|
?.split(',')
|
|
.map((origin) => origin.trim())
|
|
.filter(Boolean);
|
|
app.enableCors({
|
|
origin:
|
|
configuredOrigins?.length
|
|
? configuredOrigins
|
|
: process.env.NODE_ENV === 'production'
|
|
? false
|
|
: true,
|
|
credentials: true,
|
|
});
|
|
app.enableShutdownHooks();
|
|
app.setGlobalPrefix('api');
|
|
|
|
app.useGlobalFilters(new AllExceptionsFilter());
|
|
app.useGlobalInterceptors(new RequestIdInterceptor(), new ResponseInterceptor());
|
|
app.useGlobalPipes(new ValidationPipe());
|
|
|
|
// Swagger
|
|
const config = new DocumentBuilder()
|
|
.setTitle('Telegram User Gateway API')
|
|
.setDescription('REST API for managing Telegram user accounts via TDLib')
|
|
.setVersion('1.0')
|
|
.addBearerAuth()
|
|
.addApiKey({ type: 'apiKey', name: 'x-tenant-id', in: 'header' }, 'tenant-id')
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api/docs', app, document);
|
|
|
|
const port = process.env.PORT || 3000;
|
|
await app.listen(port);
|
|
logger.log(`Application running on http://localhost:${port}`);
|
|
logger.log(`Swagger docs at http://localhost:${port}/api/docs`);
|
|
}
|
|
|
|
bootstrap();
|