- Agent API /api/agent/v1: join with a one-time token, then poll, stats, report and export upload, all signed with the server's Ed25519 key. - Jobs signed with a separate job key (HUB_JOB_SIGNING_KEY_FILE) when delivered, config sealed to the server; one at a time per server; missed when not picked up in their window. - New install (licence, ports, preflight against the release's env template), Proxy done with public URL checks, scheduled / emergency (2FA, reason) / batch updates with email and banner, uninstall with an encrypted export first (the key is never stored), adopt and linking existing installs, purge after 30 days. - Port list, install defaults, server configuration (encrypted), stats per minute / hour with roll-up, server alerts. contracts 1.3.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.6 KiB
JavaScript
34 lines
1.6 KiB
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
|
|
const app = express();
|
|
if (process.env.TRUST_PROXY) app.set('trust proxy', parseInt(process.env.TRUST_PROXY, 10) || 1);
|
|
app.disable('x-powered-by');
|
|
|
|
// Installs call the Hub server-to-server; only the dashboard needs CORS.
|
|
app.use(cors({ origin: (process.env.FRONTEND_URL || 'http://localhost:3200').replace(/\/$/, '') }));
|
|
|
|
// Keep the exact bytes: heartbeat signatures are over the raw body. 300 KB fits the largest AI
|
|
// request the Hub accepts (utils/ai.js MAX_INPUT_TOKENS).
|
|
app.use(express.json({ limit: '1mb', verify: (req, res, buf) => { req.rawBody = buf.toString('utf8'); } }));
|
|
|
|
app.get('/api/health', (req, res) => res.json({ ok: true }));
|
|
app.use('/api/agent/v1', require('./routes/agentApi'));
|
|
app.use('/api/exports', require('./routes/exports'));
|
|
app.use('/api', require('./routes/installApi'));
|
|
app.use('/api/auth', require('./routes/auth'));
|
|
app.use('/api/admin/billing', require('./routes/billing'));
|
|
app.use('/api/admin', require('./routes/servers'));
|
|
app.use('/api/admin', require('./routes/admin'));
|
|
|
|
app.use((req, res) => res.status(404).json({ message: 'Not found', code: 'NOT_FOUND' }));
|
|
// eslint-disable-next-line no-unused-vars
|
|
app.use((err, req, res, next) => {
|
|
if (err.type === 'entity.parse.failed') return res.status(400).json({ message: 'Invalid JSON', code: 'BAD_JSON' });
|
|
if (err.type === 'entity.too.large') return res.status(413).json({ message: 'Too large', code: 'TOO_LARGE' });
|
|
console.error('[hub]', err);
|
|
res.status(500).json({ message: 'Server error', code: 'SERVER_ERROR' });
|
|
});
|
|
|
|
module.exports = app;
|