2026-09-09 06:46:27 +03:30
|
|
|
import 'reflect-metadata';
|
|
|
|
|
import { NestFactory } from '@nestjs/core';
|
|
|
|
|
import { ValidationPipe } from '@nestjs/common';
|
2026-09-13 21:02:25 +03:30
|
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
2026-09-14 20:56:17 +03:30
|
|
|
import { extname, join } from 'node:path';
|
|
|
|
|
import type { Response } from 'express';
|
2026-09-09 06:46:27 +03:30
|
|
|
import { AppModule } from './app.module';
|
2026-09-10 17:15:17 +03:30
|
|
|
import { prepareDatabase } from './prisma/bootstrap';
|
2026-09-09 06:46:27 +03:30
|
|
|
import { PrismaExceptionFilter } from './prisma/prisma-exception.filter';
|
|
|
|
|
|
2026-09-14 20:56:17 +03:30
|
|
|
// serve-static's bundled `mime` version predates .avif, so it falls back to
|
|
|
|
|
// application/octet-stream — browsers still render the image (they sniff
|
|
|
|
|
// content), but a strict client or an <img> under some CSPs would not.
|
|
|
|
|
const EXTRA_MIME_TYPES: Record<string, string> = {
|
|
|
|
|
'.avif': 'image/avif',
|
|
|
|
|
};
|
|
|
|
|
|
2026-09-09 06:46:27 +03:30
|
|
|
async function bootstrap() {
|
2026-09-10 17:15:17 +03:30
|
|
|
await prepareDatabase();
|
|
|
|
|
|
2026-09-13 21:02:25 +03:30
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
2026-09-09 06:46:27 +03:30
|
|
|
app.setGlobalPrefix('api');
|
|
|
|
|
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
|
|
|
|
app.useGlobalFilters(new PrismaExceptionFilter());
|
|
|
|
|
app.enableCors();
|
2026-09-13 21:02:25 +03:30
|
|
|
// Uploaded files, mounted OUTSIDE the /api prefix so the URLs stored on
|
|
|
|
|
// UploadedFile.url ("/uploads/<name>") resolve directly.
|
|
|
|
|
app.useStaticAssets(process.env.UPLOAD_DIR ?? join(process.cwd(), 'storage', 'uploads'), {
|
|
|
|
|
prefix: '/uploads/',
|
|
|
|
|
index: false,
|
|
|
|
|
dotfiles: 'deny',
|
2026-09-14 20:56:17 +03:30
|
|
|
setHeaders: (res: Response, path: string) => {
|
|
|
|
|
const mime = EXTRA_MIME_TYPES[extname(path).toLowerCase()];
|
|
|
|
|
if (mime) res.setHeader('Content-Type', mime);
|
|
|
|
|
},
|
2026-09-13 21:02:25 +03:30
|
|
|
});
|
|
|
|
|
// Bind all interfaces explicitly so the container is reachable from nginx.
|
|
|
|
|
await app.listen(process.env.PORT ?? 3000, '0.0.0.0');
|
2026-09-09 06:46:27 +03:30
|
|
|
}
|
|
|
|
|
bootstrap();
|