forked from AdrianCassar/Xenia-WebServices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
71 lines (61 loc) · 2.09 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'dotenv/config';
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { XeniaModule } from './src/xenia.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import PresentationSettings from 'src/infrastructure/presentation/settings/PresentationSettings';
import PersistanceSettings from 'src/infrastructure/persistance/settings/PersistanceSettings';
import compression from 'compression';
import helmet from 'helmet';
import { ConsoleLogger } from '@nestjs/common';
import fs from 'fs';
async function bootstrap() {
const logger = new ConsoleLogger('Main');
const app = await NestFactory.create<NestExpressApplication>(XeniaModule, {
rawBody: true,
});
const envs = new PersistanceSettings().get();
if (envs.swagger_API == 'true') {
const config = new DocumentBuilder()
.setTitle('Xenia Web API')
.setDescription('')
.setVersion('1.0.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
}
app.enableCors();
app.use(
helmet({
contentSecurityPolicy: {
directives: {
'script-src': [
"'self'",
"'unsafe-inline'",
"'sha256-Zww3/pDgfYVU8OPCr/mr7NFf4ZA0lY1Xeb22wR47e0w='",
],
upgradeInsecureRequests:
envs.SSL == 'true' || envs.SSL == undefined ? [] : null,
},
},
}),
);
app.use(compression());
// Support Heroku
const PORT = process.env.PORT || new PresentationSettings().get().port;
if (envs.heroku_nginx == 'true' || envs.nginx == 'true') {
// Trust the first proxy (express)
app.set('trust proxy', true);
}
// Heroku + Nginx
if (envs.heroku_nginx == 'true') {
// Listen to ngnix socket
await app.listen('/tmp/nginx.socket');
// Let Ngnix know we want to start serving from the proxy
fs.openSync('/tmp/app-initialized', 'w');
} else {
await app.listen(PORT, '0.0.0.0');
}
logger.debug(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();