import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { Logger } from 'pino-nestjs';
import { join } from 'path';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    bufferLogs: true, // Buffer logs until Pino is loaded
  });

  app.set('query parser', 'extended');
  app.useLogger(app.get(Logger));
  app.useStaticAssets(join(process.cwd(), 'public'));

  const httpInstance = app.getHttpAdapter().getInstance();

  httpInstance.get('/', (req, res) => {
    res.json({
      message: 'API furfinder!',
      version: '2.0.0',
    });
  });

  httpInstance.get('/robots.txt', (req, res) => {
    res.type('text/plain');
    res.send('User-agent: *\nDisallow: /\n');
  });

  app.setGlobalPrefix('api/v1');

  app.enableCors({
    origin: '*',
  });

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