import './config/loadEnv.js'; // .env deterministisch laden

import http from 'http';
import app from './app.js';
import { setupWebSocket } from './utils/socket.js';
import { syncDatabase } from './utils/syncDatabase.js';

const server = http.createServer(app);

setupWebSocket(server);

syncDatabase().then(() => {
  const port = process.env.PORT || 3001;
  server.listen(port, () => { 
    console.log('Server is running on port', port);
  });
}).catch(err => {
  console.error('Failed to sync database:', err);
  process.exit(1); 
});
