-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.ts
53 lines (42 loc) · 1.33 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { AppLoggerService } from './logger/services/app-logger/app-logger.service';
import { json } from 'body-parser';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import helmet from 'helmet';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
/*
Required to be executed before async storage middleware
and not loose context on POST requests
*/
app.use(json());
app.use(helmet());
app.enableShutdownHooks();
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true,
}),
);
const logger = app.get(AppLoggerService);
app.useLogger(logger);
// API docs
const config = new DocumentBuilder()
.setTitle('Node API')
.setDescription(
`<a
target="_blank"
href="https://github.com/rodion-arr/nestjs-starter-kit"
>https://github.com/rodion-arr/nestjs-starter-kit</a>`,
)
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
const port = process.env.PORT || 3000;
await app.listen(port, '0.0.0.0');
logger.log(`App started on http://localhost:${port}`);
}
bootstrap();