const { Router } = require('express'); const fetch = require('node-fetch'); const { getEnv, SERVICES, PORTS } = require('@nexusai/shared'); const router = Router(); const SERVICES_MAP = [ { key: 'inference', label: 'Inference', url: `${getEnv('INFERENCE_SERVICE_URL', SERVICES.INFERENCE_URL)}/health` }, { key: 'memory', label: 'Memory', url: `${getEnv('MEMORY_SERVICE_URL', SERVICES.MEMORY_URL)}/health` }, { key: 'embedding', label: 'Embedding', url: `${getEnv('EMBEDDING_SERVICE_URL', SERVICES.EMBEDDING_URL)}/health` }, { key: 'orchestration', label: 'Orchestration', url: `http://localhost:${getEnv('PORT', PORTS.ORCHESTRATION)}/health` }, ]; router.get('/', async (req, res) => { const results = await Promise.all( SERVICES_MAP.map(async ({ key, label, url }) => { const start = Date.now(); try { const r = await fetch(url, { signal: AbortSignal.timeout(3000) }); const data = await r.json(); return { key, label, status: 'healthy', latency: Date.now() - start, detail: data }; } catch (err) { return { key, label, status: 'unreachable', latency: Date.now() - start, detail: null }; } }) ); res.json(results); }); module.exports = router;