Signed /installs/ai/status and /installs/ai/complete (protocol 3b): the Hub holds the Claude key, holds each call's worst case against the licence's monthly cap in a locked transaction, calls Claude Haiku 5.5 and meters real cost and charged amount (markup) in rand. Settings -> AI, licence markup override, AI use on the install page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.4 KiB
JavaScript
30 lines
1.4 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: '300kb', verify: (req, res, buf) => { req.rawBody = buf.toString('utf8'); } }));
|
|
|
|
app.get('/api/health', (req, res) => res.json({ ok: true }));
|
|
app.use('/api', require('./routes/installApi'));
|
|
app.use('/api/auth', require('./routes/auth'));
|
|
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;
|