Public form file fields compress images or reject oversized files; dates use the full Jalali picker.
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { json, urlencoded } from 'express';
|
|
import type { Request } from 'express';
|
|
import { brand } from '@mento/shared';
|
|
import { AppModule } from './app.module';
|
|
|
|
async function bootstrap() {
|
|
// bodyParser خاموش تا سقف ۲ مگ برای پیوست فشردهٔ فرم عمومی + حفظ rawBody برای وبهوک
|
|
const app = await NestFactory.create(AppModule, { bodyParser: false });
|
|
app.use(
|
|
json({
|
|
limit: '2mb',
|
|
verify: (req: Request, _res, buf) => {
|
|
(req as Request & { rawBody?: Buffer }).rawBody = Buffer.from(buf);
|
|
},
|
|
}),
|
|
);
|
|
app.use(urlencoded({ extended: true, limit: '2mb' }));
|
|
const config = app.get(ConfigService);
|
|
|
|
app.setGlobalPrefix('api');
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
transform: true,
|
|
forbidNonWhitelisted: true,
|
|
}),
|
|
);
|
|
|
|
const corsRaw = config.get<string>('CORS_ORIGIN') ?? 'http://localhost:5173';
|
|
const corsOrigins = corsRaw
|
|
.split(',')
|
|
.map((origin) => origin.trim())
|
|
.filter(Boolean);
|
|
app.enableCors({
|
|
origin: corsOrigins.length <= 1 ? (corsOrigins[0] ?? 'http://localhost:5173') : corsOrigins,
|
|
credentials: true,
|
|
});
|
|
|
|
const port = Number(config.get<string>('PORT') ?? 3000);
|
|
await app.listen(port);
|
|
// eslint-disable-next-line no-console
|
|
console.log(`${brand.name} API listening on http://localhost:${port}/api`);
|
|
}
|
|
|
|
bootstrap();
|