31 lines
1005 B
TypeScript
31 lines
1005 B
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { AppModule } from './app.module.js';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { DbExceptionFilter } from './db-exception/db-exception.filter.js';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
transform: true,
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
}),
|
|
);
|
|
app.useGlobalFilters(new DbExceptionFilter());
|
|
const config = new DocumentBuilder()
|
|
.setTitle('TYT example')
|
|
.setDescription('The TYT API description')
|
|
.setVersion('1.0')
|
|
.addServer('http://localhost:3000', 'localhost')
|
|
.addTag('TYT')
|
|
.build();
|
|
const documentFactory = () => SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api', app, documentFactory, {
|
|
jsonDocumentUrl: 'swagger/json',
|
|
});
|
|
await app.listen(process.env.PORT ?? 3000);
|
|
}
|
|
bootstrap();
|