This commit is contained in:
2026-04-16 17:21:48 +03:00
parent c8fa4c442d
commit c8e7e4e927
116 changed files with 3720 additions and 4197 deletions
+42 -42
View File
@@ -1,12 +1,12 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe, Logger as NestLogger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
import helmet from 'helmet';
import * as express from 'express';
import { Logger, LoggerErrorInterceptor } from 'nestjs-pino';
import { SanitizeInterceptor } from './common/interceptors/sanitize.interceptor';
import { NestFactory } from "@nestjs/core";
import { ValidationPipe, Logger as NestLogger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
import { AppModule } from "./app.module";
import helmet from "helmet";
import * as express from "express";
import { Logger, LoggerErrorInterceptor } from "nestjs-pino";
import { SanitizeInterceptor } from "./common/interceptors/sanitize.interceptor";
// BigInt serialization polyfill — Prisma returns BigInt for mstUtc etc.
(BigInt.prototype as unknown as { toJSON: () => string }).toJSON = function () {
@@ -14,9 +14,9 @@ import { SanitizeInterceptor } from './common/interceptors/sanitize.interceptor'
};
async function bootstrap() {
const logger = new NestLogger('Bootstrap');
const logger = new NestLogger("Bootstrap");
logger.log('🔄 Starting application...');
logger.log("🔄 Starting application...");
const app = await NestFactory.create(AppModule, { bufferLogs: false });
@@ -31,33 +31,33 @@ async function bootstrap() {
app.use(helmet());
// Request payload size limit
app.use(express.json({ limit: '1mb' }));
app.use(express.urlencoded({ extended: true, limit: '1mb' }));
app.use(express.json({ limit: "1mb" }));
app.use(express.urlencoded({ extended: true, limit: "1mb" }));
// Graceful Shutdown (Prisma & Docker)
app.enableShutdownHooks();
// Get config service
const configService = app.get(ConfigService);
const port = configService.get<number>('PORT', 3005);
const nodeEnv = configService.get('NODE_ENV', 'development');
const port = configService.get<number>("PORT", 3005);
const nodeEnv = configService.get("NODE_ENV", "development");
// Enable CORS
app.enableCors({
origin:
nodeEnv === 'production'
nodeEnv === "production"
? [
'https://ui-suggestbet.bilgich.com',
'https://suggestbet.bilgich.com',
'https://iddaai.com',
'https://www.iddaai.com',
"https://ui-suggestbet.bilgich.com",
"https://suggestbet.bilgich.com",
"https://iddaai.com",
"https://www.iddaai.com",
]
: true,
credentials: true,
});
// Global prefix
app.setGlobalPrefix('api');
app.setGlobalPrefix("api");
// Validation pipe (Strict)
app.useGlobalPipes(
@@ -72,47 +72,47 @@ async function bootstrap() {
);
// Swagger setup — hidden in production
if (nodeEnv !== 'production') {
if (nodeEnv !== "production") {
const swaggerConfig = new DocumentBuilder()
.setTitle('Suggest-Bet API')
.setTitle("Suggest-Bet API")
.setDescription(
'AI-driven sports betting prediction engine with smart coupon generation',
"AI-driven sports betting prediction engine with smart coupon generation",
)
.setVersion('1.0')
.setVersion("1.0")
.addBearerAuth()
.addTag('Auth', 'Authentication endpoints')
.addTag('Users', 'User management endpoints')
.addTag('Admin', 'Admin management endpoints')
.addTag('Health', 'Health check endpoints')
.addTag('Matches', 'Match listing and detail endpoints')
.addTag('Leagues', 'League, country, and team discovery endpoints')
.addTag('Analysis', 'AI analysis and analysis history endpoints')
.addTag('Coupon', 'Coupon generation and coupon management endpoints')
.addTag('Predictions', 'Prediction and smart-coupon endpoints')
.addTag("Auth", "Authentication endpoints")
.addTag("Users", "User management endpoints")
.addTag("Admin", "Admin management endpoints")
.addTag("Health", "Health check endpoints")
.addTag("Matches", "Match listing and detail endpoints")
.addTag("Leagues", "League, country, and team discovery endpoints")
.addTag("Analysis", "AI analysis and analysis history endpoints")
.addTag("Coupon", "Coupon generation and coupon management endpoints")
.addTag("Predictions", "Prediction and smart-coupon endpoints")
.build();
logger.log('Initializing Swagger...');
logger.log("Initializing Swagger...");
const document = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('api/docs', app, document, {
SwaggerModule.setup("api/docs", app, document, {
swaggerOptions: {
persistAuthorization: true,
},
});
logger.log('Swagger initialized');
logger.log("Swagger initialized");
}
logger.log(`Attempting to listen on port ${port}...`);
await app.listen(port, '0.0.0.0');
await app.listen(port, "0.0.0.0");
logger.log('═══════════════════════════════════════════════════════════');
logger.log("═══════════════════════════════════════════════════════════");
logger.log(`🚀 Server is running on: http://localhost:${port}/api`);
logger.log(`📚 Swagger documentation: http://localhost:${port}/api/docs`);
logger.log(`💚 Health check: http://localhost:${port}/api/health`);
logger.log(`🌍 Environment: ${nodeEnv.toUpperCase()}`);
logger.log('═══════════════════════════════════════════════════════════');
logger.log("═══════════════════════════════════════════════════════════");
if (nodeEnv === 'development') {
logger.warn('⚠️ Running in development mode');
if (nodeEnv === "development") {
logger.warn("⚠️ Running in development mode");
}
}