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

const port = parseInt(process.env.PORT || '3000', 10);

async function start() {
  try {
    const { fastify } = await buildApp({ 
      port,
      searchHost: process.env.TYPESENSE_HOST || 'search',
      searchPort: parseInt(process.env.TYPESENSE_PORT || '8108', 10),
      searchApiKey: process.env.TYPESENSE_API_KEY || 'muzick-key'
    });
    await fastify.listen({ port, host: '0.0.0.0' });
    console.log(`Server listening at http://localhost:${port}`);
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
}

start();
