-
-
Notifications
You must be signed in to change notification settings - Fork 687
/
Copy pathmain.ts
74 lines (63 loc) · 2.01 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
72
73
74
import { NestFactory } from '@nestjs/core'
import * as compression from 'compression'
import { AppModule } from './app.module'
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'
import { ValidationPipe, VersioningType } from '@nestjs/common'
import { ServerConfig } from './constants'
import { InitializerService } from './initializer/initializer.service'
import { SystemDatabase, TrafficDatabase } from './system-database'
import * as helmet from 'helmet'
import * as bodyParser from 'body-parser'
async function bootstrap() {
await SystemDatabase.ready
if (ServerConfig.TRAFFIC_DATABASE_URL) {
await TrafficDatabase.ready
}
const app = await NestFactory.create(AppModule, {
logger: ['error', 'warn', 'log', 'debug', 'verbose'],
})
app.enableCors()
app.useGlobalPipes(
new ValidationPipe({
transform: true,
whitelist: true,
}),
)
app.enableVersioning({
defaultVersion: ['1'],
type: VersioningType.URI,
})
app.use(compression())
app.use(helmet.hidePoweredBy())
app.use(bodyParser.json({ limit: '1mb' }))
// for swagger api
const config = new DocumentBuilder()
.setTitle('Open API Documentation of laf')
.setDescription('`The APIs of laf server`')
// eslint-disable-next-line @typescript-eslint/no-var-requires
.setVersion(require('../package.json').version)
.addServer(ServerConfig.API_SERVER_URL, 'current server')
.addServer('http://dev.server:3000', 'dev server')
.addBearerAuth(
{ type: 'http', scheme: 'bearer', bearerFormat: 'JWT', in: 'header' },
'Authorization',
)
.build()
const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup('', app, document, {
swaggerOptions: {
persistAuthorization: true,
tagsSorter: 'alpha',
},
})
try {
const initService = app.get(InitializerService)
await initService.init()
} catch (error) {
// eslint-disable-next-line no-console
console.error(error)
process.exit(1)
}
await app.listen(3000)
}
bootstrap()