| 73 | port, |
| 74 | hostname, |
| 75 | fetch(req) { |
| 76 | const url = new URL(req.url); |
| 77 | |
| 78 | // Serve the comparison board HTML. The board JS uses relative paths |
| 79 | // (./api/feedback, ./api/progress) and a location.protocol |
| 80 | // feature-detect, so no per-request injection is needed. |
| 81 | if ( |
| 82 | req.method === "GET" && |
| 83 | (url.pathname === "/" || url.pathname === "/index.html") |
| 84 | ) { |
| 85 | return new Response(htmlContent, { |
| 86 | headers: { "Content-Type": "text/html; charset=utf-8" }, |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | // Progress polling endpoint (used by board during regeneration) |
| 91 | if (req.method === "GET" && url.pathname === "/api/progress") { |
| 92 | return Response.json({ status: state }); |
| 93 | } |
| 94 | |
| 95 | // Feedback submission from the board |
| 96 | if (req.method === "POST" && url.pathname === "/api/feedback") { |
| 97 | return handleFeedback(req); |
| 98 | } |
| 99 | |
| 100 | // Reload endpoint (used by the agent to swap in new board HTML) |
| 101 | if (req.method === "POST" && url.pathname === "/api/reload") { |
| 102 | return handleReload(req); |
| 103 | } |
| 104 | |
| 105 | return new Response("Not found", { status: 404 }); |
| 106 | }, |
| 107 | }); |
| 108 | |
| 109 | const actualPort = server.port; |