import "reflect-metadata";
import * as dotenv from "dotenv";
import * as path from "path";

dotenv.config({ path: path.resolve(process.cwd(), ".env"), override: true });

import bodyParser from "body-parser";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./modules/app.module.js";

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { logger: ["log", "error", "warn"] });

  app.enableCors({ origin: "*" });

  app.use(
    bodyParser.raw({
      type: ["application/x-amf", "application/octet-stream", "*/*"],
      limit: "20mb",
    })
  );

  const port = Number.parseInt(process.env.PORT || "8789", 10) || 8789;
  const host = process.env.HOST || "127.0.0.1";
  await app.listen(port, host);
  console.log(`NestJS server listening on http://${host}:${port}`);
}

process.on('exit', (code) => console.log('Process exiting with code:', code));

bootstrap();
