feat: establish backend foundation
This commit is contained in:
+25
-2
@@ -1,8 +1,31 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { AppModule } from './app.module';
|
||||
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
|
||||
import { Environment } from './config/env.validation';
|
||||
import { shouldExposeSwagger } from './config/swagger.config';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
const config = app.get<ConfigService<Environment, true>>(ConfigService);
|
||||
const frontendOrigin = config.getOrThrow<string>('FRONTEND_ORIGIN');
|
||||
|
||||
app.enableCors({ origin: frontendOrigin });
|
||||
app.setGlobalPrefix('api/v1');
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
|
||||
if (shouldExposeSwagger(process.env['NODE_ENV'])) {
|
||||
const document = SwaggerModule.createDocument(
|
||||
app,
|
||||
new DocumentBuilder()
|
||||
.setTitle('WealthLedger API')
|
||||
.setVersion('v1')
|
||||
.build(),
|
||||
);
|
||||
SwaggerModule.setup('api/docs', app, document);
|
||||
}
|
||||
|
||||
await app.listen(config.getOrThrow('PORT'));
|
||||
}
|
||||
bootstrap();
|
||||
void bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user