2026-09-09 17:08:47 +03:30
|
|
|
import { NestFactory } from '@nestjs/core';
|
|
|
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
|
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
|
|
|
import { json, urlencoded } from 'express';
|
|
|
|
|
import { AppModule } from './app.module';
|
2026-09-10 17:24:13 +03:30
|
|
|
import { applyPendingMigrations } from './apply-migrations';
|
2026-09-09 17:08:47 +03:30
|
|
|
|
|
|
|
|
async function bootstrap() {
|
2026-09-10 17:24:13 +03:30
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
|
await applyPendingMigrations();
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-09 17:08:47 +03:30
|
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
|
|
|
|
|
|
// تصاویر چک و رسید بهصورت base64 داخل JSON میآیند و از سقف پیشفرض ۱۰۰KB رد میشوند
|
|
|
|
|
const bodyLimit = process.env.BODY_LIMIT || '25mb';
|
|
|
|
|
app.use(json({ limit: bodyLimit }));
|
|
|
|
|
app.use(urlencoded({ extended: true, limit: bodyLimit }));
|
|
|
|
|
|
|
|
|
|
// پشت LiteSpeed روی /server → GLOBAL_PREFIX=server/api
|
|
|
|
|
const globalPrefix = process.env.GLOBAL_PREFIX || 'api';
|
|
|
|
|
app.setGlobalPrefix(globalPrefix);
|
|
|
|
|
app.enableCors({
|
|
|
|
|
origin: true,
|
|
|
|
|
credentials: true,
|
|
|
|
|
});
|
|
|
|
|
app.useGlobalPipes(
|
|
|
|
|
new ValidationPipe({
|
|
|
|
|
whitelist: true,
|
|
|
|
|
transform: true,
|
|
|
|
|
forbidNonWhitelisted: true,
|
|
|
|
|
transformOptions: { enableImplicitConversion: true },
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const swaggerConfig = new DocumentBuilder()
|
|
|
|
|
.setTitle('Fabric Trade API')
|
|
|
|
|
.setDescription('API سرور تجارت پارچه')
|
|
|
|
|
.setVersion('1.0')
|
|
|
|
|
.addBearerAuth()
|
|
|
|
|
.build();
|
|
|
|
|
const document = SwaggerModule.createDocument(app, swaggerConfig);
|
|
|
|
|
SwaggerModule.setup(`${globalPrefix}/docs`, app, document);
|
|
|
|
|
|
|
|
|
|
const port = process.env.PORT ?? 3000;
|
|
|
|
|
await app.listen(port);
|
|
|
|
|
console.log(
|
|
|
|
|
`Fabric Trade API listening on http://localhost:${port}/${globalPrefix}`,
|
|
|
|
|
);
|
|
|
|
|
console.log(`Swagger docs at http://localhost:${port}/${globalPrefix}/docs`);
|
|
|
|
|
}
|
|
|
|
|
void bootstrap();
|