Passed
Pull Request — master (#452)
by
unknown
02:52
created

main.ts ➔ bootstrap   B

Complexity

Conditions 1

Size

Total Lines 46
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 46
c 0
b 0
f 0
rs 8.92
cc 1
1
import * as path from 'path';
2
import { NestFactory } from '@nestjs/core';
3
import { ValidationPipe } from '@nestjs/common';
4
import * as helmet from 'helmet';
5
import * as cookieParser from 'cookie-parser';
6
import { NestExpressApplication } from '@nestjs/platform-express';
7
import { AppModule } from './app.module';
8
import dataSource from './datasource';
9
import { ITemplates } from './Infrastructure/Templates/ITemplates';
10
import { flashMessages } from './Infrastructure/Templates/FlashMessages';
11
import { useSession } from './Infrastructure/Security/ExpressSession';
12
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
13
14
async function bootstrap() {
15
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
16
17
  app.use(helmet());
18
  app.use(cookieParser());
19
  app.useGlobalPipes(
20
    new ValidationPipe({
21
      transform: true,
22
      transformOptions: { enableImplicitConversion: true }
23
    })
24
  );
25
26
  await useSession(app, dataSource);
27
28
  // Scalingo runs apps behind a reverse proxy
29
  app.set('trust proxy', 1);
30
31
  const assetsDir = path.join(__dirname, '..', 'public');
32
  app.useStaticAssets(assetsDir);
33
34
  const viewsDir = path.join(__dirname, '..', 'templates');
35
  app.setBaseViewsDir(viewsDir);
36
37
  const templates: ITemplates = app.get('ITemplates');
38
  templates.registerViewEngine(app, '');
39
40
  app.use(flashMessages());
41
42
  const swaggerCustomOptions = {
43
    explorer: false,
44
    customCss: '.swagger-ui .topbar { background-color: black; } .swagger-ui img { display: none; }',
45
    customSiteTitle: 'Permacoop API',
46
    customfavIcon: ""
47
  }
48
49
  const swaggerOptions = new DocumentBuilder()
50
    .setTitle('Permacoop API')
51
    .setDescription('Permacoop is an open source and eco design ERP solution reserved for worker-owned business.')
52
    .setVersion('1.0')
53
    .addBearerAuth()
54
    .build();
55
  const document = SwaggerModule.createDocument(app, swaggerOptions);
56
  SwaggerModule.setup('docs', app, document, swaggerCustomOptions);
57
58
  await app.listen(+(process.env.PORT || 3000), '0.0.0.0');
59
}
60
61
bootstrap();
62