/**
 * This is not a production server yet!
 * This is only a minimal backend to get started.
 */

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';
import { ErrorHandler } from './exception_filter/exception.fillter';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { Sentry } from '../instrument';
import { WsAdapter } from '@nestjs/platform-ws';
import { config } from 'dotenv';
config();
async function bootstrap() {
  Sentry.init();
  const app = await NestFactory.create(AppModule);
  // const globalPrefix = 'api';
  // app.setGlobalPrefix(globalPrefix);
  app.useWebSocketAdapter(new WsAdapter(app));

  app.useGlobalFilters(new ErrorHandler());
  const config = new DocumentBuilder()
    .setTitle('Twilio Service')
    .setDescription('Twilio Service API description')
    .setVersion('1.0')
    .addBearerAuth(
      { type: 'http', name: 'authorization', in: 'header' },
      'authorization'
    )
    .addServer(`${process.env.SERVER}`, 'ngrok server')
    .addServer(`http://localhost:${process.env.PORT}/`, 'local server')
    .build();
  const document = SwaggerModule.createDocument(app, config);

  SwaggerModule.setup('docs', app, document);
  const port = process.env.PORT || 3000;
  await app.listen(port);
  Logger.log(`🚀 Application is running on: http://localhost:${port}`);
}

bootstrap();
