Download apps/api/src/main.ts from qf46578/omnics: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/spaces/qf46578/omnics/resolve/main/apps/api/src/main.ts
- Command line
-
hf download hf://spaces/qf46578/omnics/apps/api/src/main.ts
-
curl -L -o main.ts https://huggingface.co/spaces/qf46578/omnics/resolve/main/apps/api/src/main.ts
2.33 kB
| import { NestFactory } from '@nestjs/core'; | |
| import { ValidationPipe } from '@nestjs/common'; | |
| import { ConfigService } from '@nestjs/config'; | |
| import helmet from 'helmet'; | |
| import compression from 'compression'; | |
| import rateLimit from 'express-rate-limit'; | |
| import { AppModule } from './app.module'; | |
| import { HttpExceptionFilter } from './common/filters/http-exception.filter'; | |
| import { TransformInterceptor } from './common/interceptors/transform.interceptor'; | |
| import { LoggerService } from './common/services/logger.service'; | |
| async function bootstrap() { | |
| const logger = new LoggerService('Bootstrap'); | |
| const app = await NestFactory.create(AppModule, { | |
| logger: ['error', 'warn', 'debug', 'verbose'], | |
| }); | |
| const configService = app.get(ConfigService); | |
| // Security | |
| app.use(helmet({ | |
| contentSecurityPolicy: { | |
| directives: { | |
| defaultSrc: ["'self'"], | |
| scriptSrc: ["'self'", "'unsafe-inline'", "'unsafe-eval'"], | |
| styleSrc: ["'self'", "'unsafe-inline'"], | |
| imgSrc: ["'self'", "data:", "https:"], | |
| connectSrc: ["'self'", "ws:", "wss:"], | |
| }, | |
| }, | |
| })); | |
| // Compression | |
| app.use(compression()); | |
| // Rate Limiting | |
| app.use(rateLimit({ | |
| windowMs: 15 * 60 * 1000, // 15 minutes | |
| max: 100, // limit each IP to 100 requests per windowMs | |
| message: 'Too many requests, please try again later.', | |
| })); | |
| // CORS | |
| app.enableCors({ | |
| origin: configService.get('CORS_ORIGIN') || '*', | |
| credentials: true, | |
| methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], | |
| allowedHeaders: ['Content-Type', 'Authorization', 'X-Request-ID'], | |
| }); | |
| // Global Pipes | |
| app.useGlobalPipes(new ValidationPipe({ | |
| whitelist: true, | |
| forbidNonWhitelisted: true, | |
| transform: true, | |
| transformOptions: { | |
| enableImplicitConversion: true, | |
| }, | |
| })); | |
| // Global Filters | |
| app.useGlobalFilters(new HttpExceptionFilter()); | |
| // Global Interceptors | |
| app.useGlobalInterceptors(new TransformInterceptor()); | |
| // Prefix | |
| app.setGlobalPrefix('api/v1'); | |
| // Port | |
| const port = configService.get<number>('PORT') || 3000; | |
| await app.listen(port); | |
| logger.log(`🚀 OmniCS API running on: http://localhost:${port}`, 'Bootstrap'); | |
| logger.log(`📚 API Documentation: http://localhost:${port}/api/v1/docs`, 'Bootstrap'); | |
| } | |
| void bootstrap(); | |