42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import './tracing.js';
|
|
import 'reflect-metadata';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { Logger, ValidationPipe } from '@nestjs/common';
|
|
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
|
|
import helmet from '@fastify/helmet';
|
|
import { AppModule } from './app.module.js';
|
|
import { mountAuthHandler } from './auth/auth.controller.js';
|
|
|
|
async function bootstrap(): Promise<void> {
|
|
if (!process.env['BETTER_AUTH_SECRET']) {
|
|
throw new Error('BETTER_AUTH_SECRET is required');
|
|
}
|
|
|
|
const logger = new Logger('Bootstrap');
|
|
const app = await NestFactory.create<NestFastifyApplication>(
|
|
AppModule,
|
|
new FastifyAdapter({ bodyLimit: 1_048_576 }),
|
|
);
|
|
|
|
await app.register(helmet as never, { contentSecurityPolicy: false });
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
|
|
mountAuthHandler(app);
|
|
|
|
const port = Number(process.env['GATEWAY_PORT'] ?? 4000);
|
|
await app.listen(port, '0.0.0.0');
|
|
logger.log(`Gateway listening on port ${port}`);
|
|
}
|
|
|
|
bootstrap().catch((err: unknown) => {
|
|
const logger = new Logger('Bootstrap');
|
|
logger.error('Fatal startup error', err instanceof Error ? err.stack : String(err));
|
|
process.exit(1);
|
|
});
|