Hub v1: install API, licences, health dashboard, alerts
- Protocol 1 (docs/hub-protocol.md): public key, register, signed heartbeats - Ed25519 licence tokens (30-day validity, status, expiry, grace, limits) - Dashboard: installs, install detail, customers and licences, alerts, settings and audit log; two-factor login required - Alert checks every 5 minutes, emailed once; heartbeat roll-up after 30 days - Unit tests for encryption, tokens, signatures, TOTP and alert rules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
require('dotenv').config();
|
||||
|
||||
const required = ['DATABASE_URL', 'JWT_SECRET', 'HUB_ENCRYPTION_KEY'];
|
||||
const missing = required.filter(k => !process.env[k]);
|
||||
if (missing.length) {
|
||||
console.error(`[hub] Missing environment variables: ${missing.join(', ')} (see .env.example)`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const app = require('./app');
|
||||
const { keyPair } = require('./utils/licenceToken');
|
||||
const { runAlerts, rollupHeartbeats } = require('./utils/alerts');
|
||||
|
||||
// Fail early if the licence signing key is missing or wrong.
|
||||
try {
|
||||
keyPair();
|
||||
} catch (e) {
|
||||
console.error(`[hub] ${e.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const PORT = parseInt(process.env.PORT || '5200', 10);
|
||||
app.listen(PORT, () => console.log(`[hub] Listening on ${PORT}`));
|
||||
|
||||
// Background checks: alerts every 5 minutes, heartbeat roll-up once a day. The Hub runs as a
|
||||
// single process, so plain timers are enough.
|
||||
if (String(process.env.JOBS_ENABLED || 'true').toLowerCase() !== 'false') {
|
||||
const every = (ms, name, fn) => setInterval(() => fn().catch(e => console.warn(`[hub] ${name} failed:`, e?.message || e)), ms);
|
||||
every(5 * 60 * 1000, 'alerts', () => runAlerts());
|
||||
every(24 * 60 * 60 * 1000, 'heartbeat roll-up', () => rollupHeartbeats());
|
||||
setTimeout(() => runAlerts().catch(() => {}), 30 * 1000);
|
||||
}
|
||||
Reference in New Issue
Block a user