import dotenv from 'dotenv';
import { buildApp } from './app';

dotenv.config();

const port = Number(process.env.PORT ?? 3000);
const app = buildApp();

const start = async () => {
  try {
    await app.listen({ port, host: '0.0.0.0' });
    // eslint-disable-next-line no-console
    console.log(`Server listening on http://0.0.0.0:${port}`);
  } catch (err) {
    app.log.error(err);
    process.exit(1);
  }
};

// Start only when run directly (avoids starting during tests)
if (require.main === module) {
  start();
}

/**
 * Metadatos:
 * Autor: GitHub Copilot
 * Última actualización: 2026-02-07
 */
