-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathmain.ts
More file actions
111 lines (100 loc) · 3.21 KB
/
main.ts
File metadata and controls
111 lines (100 loc) · 3.21 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { NestFactory } from '@nestjs/core';
import { Logger } from '@nestjs/common';
import { CustomConsoleLogger } from './logger/logger';
import { LogLevel } from '@nestjs/common/services/logger.service';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
import { DatabaseService } from './database/database.service';
import helmet from 'helmet';
import * as dotenv from 'dotenv';
dotenv.config();
async function bootstrap() {
const logLevels = process.env.LOGLEVEL?.split(',') ?? [
'log',
'fatal',
'error',
'warn',
'debug',
'verbose',
];
Logger.log(`Log levels: ${logLevels}`, 'Bootstrap');
const app = await NestFactory.create(AppModule, {
logger: new CustomConsoleLogger({
prefix: 'Kubero',
logLevels: logLevels as LogLevel[],
}),
cors: true,
});
await DatabaseService.DBinit();
app.use(
helmet({
contentSecurityPolicy: false,
strictTransportSecurity: false,
crossOriginOpenerPolicy: false,
crossOriginEmbedderPolicy: false,
/* suggested settings. Requires further testing.
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", "example.com"],
styleSrc: ["'self'", "example.com"],
imgSrc: ["'self'", "data:"],
connectSrc: ["'self'"],
fontSrc: ["'self'", "https:", "data:"],
objectSrc: ["'none'"],
frameAncestors: ["'self'"],
formAction: ["'self'"],
upgradeInsecureRequests: [],
},
},
frameguard: { action: 'deny' },
strictTransportSecurity: { maxAge: 63072000, includeSubDomains: true },
crossOriginOpenerPolicy: { policy: 'same-origin' },
crossOriginEmbedderPolicy: { policy: 'require-corp' },
*/
}),
);
const config = new DocumentBuilder()
.setTitle('Kubero')
.setDescription(
'Kubero is a web-based tool deploy applications on a Kubernetes clusters. It provides a simple and intuitive interface to manage your clusters, applications, and pipelines.',
)
.setVersion('3.0')
.addServer('/', 'Local (default)')
.addSecurity('bearerAuth', {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
})
.addSecurity('oauth2', {
type: 'oauth2',
flows: {
implicit: {
authorizationUrl: 'http://example.org/api/oauth/dialog',
scopes: {
'write:example': 'modify pets in your example',
'read:example': 'read your example',
},
},
},
})
.build();
const documentFactory = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api/docs', app, documentFactory, {
customSiteTitle: 'Kubero API Documentation',
//customfavIcon: '/favicon.ico',
swaggerOptions: {
tagsSorter: 'alpha',
persistAuthorization: true,
displayRequestDuration: true,
//docExpansion: 'none', // 'none' to collapse all sections by default
},
});
await app.listen(process.env.PORT ?? 2000); // Use port 2000 for compatibility with kubero v2
Logger.log(
`⚡️[server]: Server is running at: ${await app.getUrl()}`,
'Bootstrap',
);
//app.enableShutdownHooks();
}
bootstrap();