import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import {MicroserviceOptions, Transport} from '@nestjs/microservices';
import * as process from "process";
import {MongoIoAdapter} from "./socket/mongoio-adapter";
import {ConfigService} from "@nestjs/config";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const mongoIoAdapter = new MongoIoAdapter(app);
  const configService = app.get(ConfigService);
  await mongoIoAdapter.connectToMongo(configService);
  app.useWebSocketAdapter(mongoIoAdapter);
  app.enableCors({
    origin: '*',
  });

  app.connectMicroservice<MicroserviceOptions>({
    transport: Transport.RMQ,
    options: {
      urls: [process.env.RMQ_URL],
      queue: process.env.RMQ_QUEUE,
      queueOptions: {
        durable: false,

      }
    }
  })
  await app.startAllMicroservices();
  await app.listen(process.env.PORT || 3000);
}
bootstrap();
