import 'dotenv/config';
import { buildApp } from './app.js';
import { runMigrations } from './db/migrate.js';

const PORT = Number(process.env.PORT || 6001);

async function main() {
  console.log('Running migrations...');
  await runMigrations();

  const app = await buildApp();
  await app.listen({ port: PORT, host: '0.0.0.0' });
  console.log(`Server running on http://localhost:${PORT}`);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
