File size: 1,111 Bytes
c33bf01 70a2f38 c33bf01 70a2f38 c33bf01 70a2f38 c33bf01 c2b1c17 c33bf01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | require('dotenv').config();
const app = require('./app');
const omada = require('./services/omada');
const { initJobs } = require('./jobs');
const { runMigrations } = require('./utils/migrate');
const PORT = process.env.PORT || 3000;
async function start() {
// 1. Run DB migrations
try {
await runMigrations();
} catch (err) {
console.error('[Boot] Migration failed — aborting:', err.message);
process.exit(1);
}
// 2. Boot Omada connection
try {
await omada.initOmada();
} catch (err) {
console.error('[Boot] Omada init failed:', err.message);
console.warn('[Boot] Continuing without Omada — check OMADA_URL / credentials');
}
// 3. Start background jobs
initJobs();
// 3. Listen
app.listen(PORT, () => {
console.log(`[Server] Listening on http://0.0.0.0:${PORT}`);
const host = (process.env.PORTAL_HOST || '').replace(/^https?:\/\//, '');
console.log(`[Server] Portal base: ${process.env.PORTAL_SCHEME || 'http'}://${host}`);
});
}
start().catch(err => {
console.error('[Boot] Fatal error:', err.message);
process.exit(1);
});
|