homemanager-be/src/main.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-12 18:10:36 +00:00
import { ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get(ConfigService);
2023-01-18 20:48:58 +00:00
app.enableCors({
origin: configService.get('FRONTEND_URL'),
});
2023-01-12 18:10:36 +00:00
const config = new DocumentBuilder()
.setTitle('Home Manager')
.setDescription('Home manager API')
.setVersion('1.0')
.addTag('users')
.addTag('groups')
.addTag('storage')
.addTag('buildings')
2023-01-15 06:42:40 +00:00
.addSecurity('Bearer token', {
name: 'Authorization',
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
in: 'header',
2023-01-12 18:10:36 +00:00
})
2023-01-15 06:42:40 +00:00
.addSecurity('Email and Password', {
2023-01-13 19:42:21 +00:00
type: 'http',
2023-01-15 06:42:40 +00:00
description: 'For acquiring the access token',
scheme: 'basic',
2023-01-13 19:42:21 +00:00
})
2023-01-12 18:10:36 +00:00
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
app.useGlobalPipes(
new ValidationPipe({
forbidNonWhitelisted: true,
whitelist: true,
}),
);
2023-01-19 15:08:17 +00:00
await app.listen(+configService.get('PORT'), configService.get('HOST'));
2023-01-12 18:10:36 +00:00
}
bootstrap();