import dotenv from 'dotenv';
import app from './src/app.js';
import { testConnection } from './src/config/db.js';
import { startDomainRenewalAlertScheduler } from './src/services/domainRenewalAlertService.js';

dotenv.config();

const PORT = process.env.PORT || 3000;
const HOST = '0.0.0.0';

const startServer = async () => {
    const isDbConnected = await testConnection();

    if (!isDbConnected) {
        console.log('Server not started because database connection failed.');
        return;
    }

    app.listen(PORT, HOST, () => {
        console.log(`Server running at http://192.168.29.207:${PORT}`);
        startDomainRenewalAlertScheduler();
    });
};

startServer();
