import 'dotenv/config';
import Fastify from 'fastify';
import cors from '@fastify/cors';
import { generateRoutes } from './routes/generate.js';
import { publishRoutes } from './routes/publish.js';

const app = Fastify({ logger: true });

await app.register(cors, { origin: true });
await app.register(generateRoutes);
await app.register(publishRoutes);

const port = parseInt(process.env['GENERATION_PORT'] ?? '3002', 10);

try {
  await app.listen({ port, host: '0.0.0.0' });
} catch (err) {
  app.log.error(err);
  process.exit(1);
}
