gateway/src/main.ts

34 lines
980 B
TypeScript

import { Logger } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { NestFactory } from '@nestjs/core'
import { SwaggerModule } from '@nestjs/swagger'
import { AppModule } from './core/app.module'
import { getCorsConfig, swaggerConfig, validationPipe } from './core/config'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
const logger = new Logger()
const config = app.get(ConfigService)
app.useGlobalPipes(validationPipe)
app.enableCors(getCorsConfig(config))
const swaggerDocument = SwaggerModule.createDocument(app, swaggerConfig)
SwaggerModule.setup('docs', app, swaggerDocument, {
yamlDocumentUrl: '/docs/openapi.yaml'
})
const port = config.getOrThrow<number>('HTTP_PORT')
const host = config.getOrThrow<string>('HTTP_HOST')
await app.listen(port)
logger.log(`Gateway started: ${host}`)
logger.log(`Healthcheck: ${host}health`)
logger.log(`Swagger: ${host}docs`)
}
bootstrap()