46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { NestFactory } from "@nestjs/core";
|
|
import { ValidationPipe } from "@nestjs/common";
|
|
import { NestExpressApplication } from "@nestjs/platform-express";
|
|
import { IoAdapter } from "@nestjs/platform-socket.io";
|
|
import { join } from "path";
|
|
import { AppModule } from "./app.module";
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
|
|
|
const corsOrigins = (process.env.CORS_ORIGINS ?? "http://localhost:3000")
|
|
.split(",")
|
|
.map((o) => o.trim());
|
|
|
|
app.enableCors({
|
|
origin: corsOrigins,
|
|
credentials: true,
|
|
});
|
|
|
|
// Socket.io adapter for WebSocket gateway (C-6)
|
|
app.useWebSocketAdapter(new IoAdapter(app));
|
|
|
|
app.setGlobalPrefix("api");
|
|
|
|
// Serve uploaded files (photos, invoices) as static assets
|
|
const uploadsDir = join(process.cwd(), "uploads");
|
|
app.useStaticAssets(uploadsDir, { prefix: "/uploads" });
|
|
|
|
// Validación global de DTOs (class-validator)
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: false,
|
|
transform: true,
|
|
transformOptions: { enableImplicitConversion: true },
|
|
}),
|
|
);
|
|
|
|
const port = process.env.API_PORT ?? process.env.PORT ?? 3001;
|
|
await app.listen(port, "0.0.0.0");
|
|
|
|
console.log(`Moraworld API → http://localhost:${port}/api`);
|
|
}
|
|
|
|
bootstrap();
|