48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
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';
|
||
|
|
|
||
|
|
async function bootstrap() {
|
||
|
|
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();
|