const { createApp } = require('./server'); const { initDB } = require('./db'); const { OLIST_SYNC_ENABLED, PORT } = require('./config'); const { markInterruptedOlistRuns, scheduleOlistSync } = require('./services/olistService'); const start = async () => { await initDB(); await markInterruptedOlistRuns(); const app = createApp(); if (OLIST_SYNC_ENABLED) scheduleOlistSync(); app.listen(PORT, '0.0.0.0', () => { console.log(`Nexstar Backend running at http://localhost:${PORT}`); console.log(`Endpoint for n8n: POST http://localhost:${PORT}/api/data`); console.log(`Scheduled campaign processor: POST http://localhost:${PORT}/api/internal/process-stock-campaigns`); }); }; start().catch((error) => { console.error('Failed to start backend:', error); process.exit(1); });