MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / bootstrap

Function bootstrap

backend/api/src/main.ts:12–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10} from './utils/cors.utils';
11
12async function bootstrap() {
13 const app = await NestFactory.create(AppModule);
14 const isProduction = process.env.NODE_ENV === 'production';
15
16 if (isProduction) {
17 app.use(helmet());
18 app.use(compression());
19 }
20
21 // Enable cookie parsing
22 app.use(cookieParser());
23
24 // Enable CORS for frontend
25 const allowedOrigins = parseAllowedOrigins(process.env.ALLOWED_ORIGINS, [
26 process.env.FRONTEND_URL || 'http://localhost:5173',
27 ]);
28
29 app.enableCors({
30 origin: createCorsOriginChecker(allowedOrigins),
31 methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
32 allowedHeaders: ['Content-Type', 'Authorization', 'Cache-Control'],
33 exposedHeaders: ['Content-Type'],
34 credentials: true, // Required for cookies
35 });
36
37 // Enable global validation
38 app.useGlobalPipes(
39 new ValidationPipe({
40 whitelist: true,
41 forbidNonWhitelisted: true,
42 transform: true,
43 }),
44 );
45
46 // Set global prefix
47 app.setGlobalPrefix('api');
48
49 const port = process.env.PORT || 3001;
50 await app.listen(port);
51
52 const protocol = isProduction ? 'https' : 'http';
53 const host = isProduction ? 'production' : 'localhost';
54
55 console.log(
56 `🚀 DataKit API is running on: ${protocol}://${host}:${port}/api`,
57 );
58 console.log(
59 `📊 Health check available at: ${protocol}://${host}:${port}/api/health`,
60 );
61 console.log(`🌍 Environment: ${process.env.NODE_ENV || 'development'}`);
62}
63bootstrap();

Callers 1

main.tsFile · 0.85

Calls 3

parseAllowedOriginsFunction · 0.90
createCorsOriginCheckerFunction · 0.90
createMethod · 0.45

Tested by

no test coverage detected