feat: bootstrap from Fabric monorepo
This commit is contained in:
56
src/main.ts
Normal file
56
src/main.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'reflect-metadata';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { AppModule } from './app.module';
|
||||
import { createRequestContextMiddleware } from './common/request-context.middleware';
|
||||
import { MetricsService } from './common/metrics.service';
|
||||
|
||||
function requireEnv(name: string): string {
|
||||
const value = process.env[name];
|
||||
if (!value || value.trim() === '') {
|
||||
throw new Error(`Missing required env: ${name}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function validateEnv(): void {
|
||||
requireEnv('DB_HOST');
|
||||
requireEnv('DB_PORT');
|
||||
requireEnv('DB_USER');
|
||||
requireEnv('DB_PASSWORD');
|
||||
requireEnv('DB_NAME');
|
||||
requireEnv('CENTER_SHARED_SECRET');
|
||||
requireEnv('JWT_ACCESS_SECRET');
|
||||
requireEnv('JWT_REFRESH_SECRET');
|
||||
}
|
||||
|
||||
async function bootstrap() {
|
||||
validateEnv();
|
||||
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.setGlobalPrefix('api');
|
||||
const metrics = app.get(MetricsService);
|
||||
app.use(createRequestContextMiddleware('center', metrics));
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
}),
|
||||
);
|
||||
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.setTitle('Fabric Backend Center API')
|
||||
.setDescription('Identity Hub APIs for Fabric')
|
||||
.setVersion('1.0.0')
|
||||
.build();
|
||||
const swaggerDoc = SwaggerModule.createDocument(app, swaggerConfig);
|
||||
SwaggerModule.setup('docs', app, swaggerDoc);
|
||||
|
||||
const port = process.env.PORT ? Number(process.env.PORT) : 7001;
|
||||
await app.listen(port);
|
||||
console.log(`Fabric.Backend.Center listening on :${port}`);
|
||||
}
|
||||
|
||||
void bootstrap();
|
||||
Reference in New Issue
Block a user