-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.ts
47 lines (40 loc) · 1.55 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
import 'dotenv/config';
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ExpressAdapter } from '@nestjs/platform-express';
import * as http from 'http';
import * as https from 'https';
import { SunriseModule } from './src/sunrise.module';
import PresentationSettings from 'src/infrastructure/presentation/settings/PresentationSettings';
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import { readFileSync } from 'fs';
import * as express from 'express';
import { ShutdownObserver } from 'src/ShutdownObserver';
async function bootstrap() {
const server = express();
const app = await NestFactory.create(
SunriseModule,
new ExpressAdapter(server),
);
const config = new DocumentBuilder()
.setTitle('Sunrise')
.setDescription('Halo 3 Web API')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
app.enableCors();
await app.init();
const httpServer = http.createServer(server).listen(process.env.HTTP_PORT);
const shutdownObserver = app.get(ShutdownObserver);
shutdownObserver.addHttpServer(httpServer);
if (process.env.USE_HTTPS=== 'true') {
const httpsOptions = {
key: readFileSync(process.env.SSL_PRIVATE_KEY_PATH),
cert: readFileSync(process.env.SSL_CERTIFICATE_PATH),
};
const httpsServer = https.createServer(httpsOptions, server).listen(process.env.HTTPS_PORT);
shutdownObserver.addHttpServer(httpsServer);
}
}
bootstrap();