(req)
| 31 | const server = Bun.serve({ |
| 32 | port: PORT, |
| 33 | async fetch(req) { |
| 34 | const url = new URL(req.url); |
| 35 | |
| 36 | // CORS preflight |
| 37 | if (req.method === "OPTIONS") { |
| 38 | return new Response(null, { status: 204, headers: corsHeaders }); |
| 39 | } |
| 40 | |
| 41 | // Health check |
| 42 | if (url.pathname === "/health" && req.method === "GET") { |
| 43 | return Response.json({ status: "ok" }, { headers: corsHeaders }); |
| 44 | } |
| 45 | |
| 46 | // Debug endpoint |
| 47 | if (url.pathname === "/debug" && req.method === "POST") { |
| 48 | const body = await req.json().catch(() => null); |
| 49 | if (!body || !body.label) { |
| 50 | return new Response("Missing required field: label", { |
| 51 | status: 400, |
| 52 | headers: corsHeaders, |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | await appendToLog(body.label, body.data); |
| 57 | console.log(`[LOG] ${body.label}`, body.data ? JSON.stringify(body.data) : ""); |
| 58 | |
| 59 | return Response.json({ received: true }, { headers: corsHeaders }); |
| 60 | } |
| 61 | |
| 62 | return new Response("Not found", { status: 404, headers: corsHeaders }); |
| 63 | }, |
| 64 | }); |
| 65 | |
| 66 | console.log(`Debug server running at http://localhost:${PORT}`); |
no test coverage detected