// Claus Network API status reporter, by MVA (agentminimum.com). // Runs server-side so browser CORS never matters. No keys, no wallets, no cookies, no logging of visitors. const BASE = 'https://claus-network-api.vercel.app'; const CHECKS = [ { name: 'health', path: '/health' }, { name: 'capabilities', path: '/v1/public/capabilities' } ]; const TIMEOUT_MS = 10000; async function probe(check) { const url = BASE + check.path; const started = Date.now(); const observed_at = new Date(started).toISOString(); const ctrl = new AbortController(); const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS); try { const res = await fetch(url, { signal: ctrl.signal, headers: { accept: 'application/json' }, cache: 'no-store' }); const text = await res.text(); const latency_ms = Date.now() - started; let body = null; try { body = JSON.parse(text); } catch (e) { body = null; } let state = 'OK'; let reason = null; if (!res.ok) { state = 'UNAVAILABLE'; reason = 'HTTP ' + res.status; } else if (body === null) { state = 'UNAVAILABLE'; reason = 'response was not JSON'; } else if (body && (body.ok === false || ['error', 'down', 'unhealthy'].includes(String(body.status || '').toLowerCase()))) { state = 'UNAVAILABLE'; reason = 'endpoint reported itself unhealthy'; } return { name: check.name, url, observed_at, latency_ms, http_status: res.status, state, reason, sample: state === 'OK' ? text.slice(0, 600) : text.slice(0, 300) }; } catch (err) { const aborted = err && err.name === 'AbortError'; return { name: check.name, url, observed_at, latency_ms: Date.now() - started, http_status: null, state: 'UNAVAILABLE', reason: aborted ? 'timed out after ' + TIMEOUT_MS + ' ms' : 'request failed: ' + String(err && err.message || err), sample: null }; } finally { clearTimeout(timer); } } module.exports = async (req, res) => { const results = await Promise.all(CHECKS.map(probe)); res.setHeader('Cache-Control', 'no-store, max-age=0'); res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Content-Type', 'application/json; charset=utf-8'); res.status(200).send(JSON.stringify({ reporter: 'MVA Claus status reporter', generated_at: new Date().toISOString(), overall: results.every(r => r.state === 'OK') ? 'OK' : 'UNAVAILABLE', checks: results }, null, 2)); };