Spaces:
Running
Running
Download src/main.ts from IlyasDaoud/omnia-eats-api: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/spaces/IlyasDaoud/omnia-eats-api/resolve/main/src/main.ts
- Command line
-
hf download hf://spaces/IlyasDaoud/omnia-eats-api/src/main.ts
-
curl -L -o main.ts https://huggingface.co/spaces/IlyasDaoud/omnia-eats-api/resolve/main/src/main.ts
1.77 kB
| import { NestFactory } from '@nestjs/core'; | |
| import { ValidationPipe, Logger } from '@nestjs/common'; | |
| import { ConfigService } from '@nestjs/config'; | |
| import helmet from 'helmet'; | |
| import { AppModule } from './app.module'; | |
| async function bootstrap() { | |
| const app = await NestFactory.create(AppModule, { bufferLogs: false }); | |
| const config = app.get(ConfigService); | |
| const logger = new Logger('Bootstrap'); | |
| // Security headers (JSON API β CSP off; CORP cross-origin so assets + CORS work). | |
| app.use(helmet({ contentSecurityPolicy: false, crossOriginResourcePolicy: { policy: 'cross-origin' } })); | |
| app.getHttpAdapter().getInstance().set('trust proxy', 1); | |
| // CORS β allow the configured frontend origins (Eats web + agent app). | |
| // Mirror localhost β 127.0.0.1 since the browser treats them as distinct origins. | |
| // In production set CORS_ORIGINS to your EXACT domains (no wildcards). | |
| const origins = corsOrigins(config.get<string>('CORS_ORIGINS') ?? 'http://localhost:5182,http://localhost:5180'); | |
| app.enableCors({ origin: origins, credentials: true }); | |
| app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true })); | |
| const port = config.get<number>('PORT') ?? 3002; | |
| await app.listen(port); | |
| logger.log(`OMNIA Eats backend listening on http://localhost:${port}`); | |
| } | |
| /** Expand origins, mirroring localhost β 127.0.0.1 (separate browser origins). */ | |
| function corsOrigins(raw: string): string[] { | |
| const set = new Set<string>(); | |
| for (const o of raw.split(',').map((s) => s.trim()).filter(Boolean)) { | |
| set.add(o); | |
| if (o.includes('localhost')) set.add(o.replace('localhost', '127.0.0.1')); | |
| else if (o.includes('127.0.0.1')) set.add(o.replace('127.0.0.1', 'localhost')); | |
| } | |
| return [...set]; | |
| } | |
| bootstrap(); | |