forked from Frankencoin-ZCHF/frankencoin-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi.main.ts
More file actions
46 lines (41 loc) · 1.32 KB
/
api.main.ts
File metadata and controls
46 lines (41 loc) · 1.32 KB
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
import { ConsoleLogger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { logConfig } from 'api.config';
import { WinstonModule } from 'nest-winston';
import { format, transports } from 'winston';
import { AppModule } from './api.module';
// import * as dotenv from 'dotenv';
// dotenv.config();
async function bootstrap() {
const logger = ['dev', 'prd'].includes(process.env.API_ENVIRONMENT)
? WinstonModule.createLogger({
level: process.env.LOG_LEVEL ? process.env.LOG_LEVEL : 'info',
transports: [
new transports.Console({
format: format.combine(
format.printf((info) => {
return `${info.level} [${info.context}]: ${info.message}`;
})
),
}),
],
})
: new ConsoleLogger();
const api = await NestFactory.create(AppModule, { cors: true, logger });
const config = new DocumentBuilder()
.setTitle(process.env.npm_package_name)
.setDescription('The API description')
.setVersion(process.env.npm_package_version)
.build();
const document = SwaggerModule.createDocument(api, config);
SwaggerModule.setup('/', api, document, {
swaggerOptions: {
persistAuthorization: true,
},
});
// Startup Message
logConfig();
await api.listen(process.env.PORT || 3000);
}
bootstrap();