-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathmain.ts
55 lines (45 loc) · 1.69 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
54
55
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { json, urlencoded } from 'body-parser';
import { useContainer } from 'class-validator';
import { AppModule } from './app.module';
import { ConfigNames } from './common/config';
import { INestApplication } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create<INestApplication>(AppModule, {
cors: true,
});
const configService: ConfigService = app.get(ConfigService);
const host = configService.get<string>(ConfigNames.HOST)!;
const port = configService.get<string>(ConfigNames.PORT)!;
app.enableCors({
origin:
process.env.NODE_ENV === 'development' ||
process.env.NODE_ENV === 'staging'
? [
`http://localhost:${port}`,
`http://127.0.0.1:${port}`,
`http://0.0.0.0:${port}`,
`http://${host}:${port}`,
]
: [`http://${host}:${port}`],
credentials: true,
exposedHeaders: ['Content-Disposition'],
});
useContainer(app.select(AppModule), { fallbackOnErrors: true });
app.use(json({ limit: '5mb' }));
app.use(urlencoded({ limit: '5mb', extended: true }));
const config = new DocumentBuilder()
.addBearerAuth()
.setTitle('Fortune Exchange Oracle API')
.setDescription('Swagger Fortune Exchange Oracle API')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('swagger', app, document);
await app.listen(port, host, async () => {
console.info(`API server is running on http://${host}:${port}`);
});
}
void bootstrap();