import { config } from 'dotenv';
import { resolve } from 'path';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { configureApplication } from './app.config';

// `dev:api` runs via the `apps/api` npm workspace, so process.cwd() is
// `apps/api`, not the repo root where the documented `.env` lives. Resolve
// it explicitly so `npm run dev:api` picks up `DATABASE_URL` after
// `Copy-Item .env.example .env` as documented in the README.
config({ path: resolve(__dirname, '..', '..', '..', '.env') });

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  configureApplication(app);
  app.enableShutdownHooks();
  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
