| 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() { |
| |
| 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); |
| } |
|
|
| |
| try { |
| await omada.initOmada(); |
| } catch (err) { |
| console.error('[Boot] Omada init failed:', err.message); |
| console.warn('[Boot] Continuing without Omada — check OMADA_URL / credentials'); |
| } |
|
|
| |
| initJobs(); |
|
|
| |
| 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); |
| }); |
|
|