|
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: |
|
45
|
|
|
'.swagger-ui .topbar { background-color: black; } .swagger-ui img { display: none; }', |
|
46
|
|
|
customSiteTitle: 'Permacoop API', |
|
47
|
|
|
customfavIcon: '' |
|
48
|
|
|
}; |
|
49
|
|
|
|
|
50
|
|
|
const swaggerOptions = new DocumentBuilder() |
|
51
|
|
|
.setTitle('Permacoop API') |
|
52
|
|
|
.setDescription( |
|
53
|
|
|
'Permacoop is an open source and eco design ERP solution reserved for worker-owned business.' |
|
54
|
|
|
) |
|
55
|
|
|
.setVersion('1.0') |
|
56
|
|
|
.addBearerAuth() |
|
57
|
|
|
.build(); |
|
58
|
|
|
const document = SwaggerModule.createDocument(app, swaggerOptions); |
|
59
|
|
|
SwaggerModule.setup('docs', app, document, swaggerCustomOptions); |
|
60
|
|
|
|
|
61
|
|
|
await app.listen(+(process.env.PORT || 3000), '0.0.0.0'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
bootstrap(); |
|
65
|
|
|
|