// ─── Strata Analysis Container Server ──────────────────────────────── // HTTP server running inside the Cloudflare Container. // Accepts analysis requests, reads vault + carry from R2, returns // structured analysis. import { analyze } from "./analysis.js"; import { createServer } from "http"; const PORT = 8080; createServer(async (req, res) => { const url = new URL(req.url || "/", `http://localhost:${PORT}`); if (url.pathname === "/analyze" && req.method === "POST") { const chunks: Buffer[] = []; for await (const chunk of req) chunks.push(chunk); const body = Buffer.concat(chunks).toString(); try { const input = JSON.parse(body); const result = await analyze(input); res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify(result)); } catch (e: any) { console.error("Analysis error:", e); res.writeHead(500, { "Content-Type": "application/json" }); res.end(JSON.stringify({ error: e.message })); } return; } if (url.pathname === "/health") { res.writeHead(200); res.end("ok"); return; } res.writeHead(404); res.end("Not found"); }).listen(PORT, () => { console.log(`Strata analysis container listening on port ${PORT}`); });