This repository has no description
1.3 kB
42 lines
1// ─── Strata Analysis Container Server ────────────────────────────────
2// HTTP server running inside the Cloudflare Container.
3// Accepts analysis requests, reads vault + carry from R2, returns
4// structured analysis.
5
6import { analyze } from "./analysis.js";
7import { createServer } from "http";
8
9const PORT = 8080;
10
11createServer(async (req, res) => {
12 const url = new URL(req.url || "/", `http://localhost:${PORT}`);
13
14 if (url.pathname === "/analyze" && req.method === "POST") {
15 const chunks: Buffer[] = [];
16 for await (const chunk of req) chunks.push(chunk);
17 const body = Buffer.concat(chunks).toString();
18
19 try {
20 const input = JSON.parse(body);
21 const result = await analyze(input);
22 res.writeHead(200, { "Content-Type": "application/json" });
23 res.end(JSON.stringify(result));
24 } catch (e: any) {
25 console.error("Analysis error:", e);
26 res.writeHead(500, { "Content-Type": "application/json" });
27 res.end(JSON.stringify({ error: e.message }));
28 }
29 return;
30 }
31
32 if (url.pathname === "/health") {
33 res.writeHead(200);
34 res.end("ok");
35 return;
36 }
37
38 res.writeHead(404);
39 res.end("Not found");
40}).listen(PORT, () => {
41 console.log(`Strata analysis container listening on port ${PORT}`);
42});