(req)
| 159 | return Bun.serve({ |
| 160 | port, |
| 161 | async fetch(req) { |
| 162 | const url = new URL(req.url); |
| 163 | |
| 164 | // Handle CORS preflight requests |
| 165 | if (req.method === "OPTIONS") { |
| 166 | return new Response(null, { status: 204, headers: corsHeaders }); |
| 167 | } |
| 168 | |
| 169 | if (url.pathname === config.healthEndpoint && req.method === "GET") { |
| 170 | return jsonResponse({ status: "ok" }); |
| 171 | } |
| 172 | |
| 173 | if (url.pathname === config.endpoint && req.method === "POST") { |
| 174 | const body = await req.json().catch(() => null); |
| 175 | if (!body || !body.label) { |
| 176 | return new Response("Missing required field: label", { |
| 177 | status: 400, |
| 178 | headers: corsHeaders, |
| 179 | }); |
| 180 | } |
| 181 | await appendToLog(logPath, body.label, body.data); |
| 182 | return jsonResponse({ received: true }); |
| 183 | } |
| 184 | |
| 185 | return new Response("Not found", { status: 404, headers: corsHeaders }); |
| 186 | }, |
| 187 | }); |
| 188 | } |
| 189 |
nothing calls this directly
no test coverage detected