File size: 1,564 Bytes
c33bf01 2324ed0 c33bf01 70a2f38 c33bf01 70a2f38 f63dc3d c4ec39b 70a2f38 c33bf01 70a2f38 c33bf01 c2b1c17 c33bf01 f63dc3d 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 43 44 45 46 47 48 49 50 51 | require('dotenv').config();
require('./utils/logger').install();
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);
if (err.stack) console.error(err.stack);
if (err.errno || err.code || err.sqlState) {
console.error('[Boot] DB error:', JSON.stringify({ errno: err.errno, code: err.code, sqlState: err.sqlState, sqlMessage: err.sqlMessage }));
}
if (err.migrationContext) {
console.error('[Boot] Migration context:', JSON.stringify(err.migrationContext));
}
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);
if (err.stack) console.error(err.stack);
process.exit(1);
});
|