(req)
| 221 | port: 0, |
| 222 | hostname: "127.0.0.1", |
| 223 | fetch(req) { |
| 224 | const url = new URL(req.url); |
| 225 | if (url.pathname === "/openapi.json") return Response.json(spec); |
| 226 | |
| 227 | if (url.pathname === "/pets" && req.method === "GET") { |
| 228 | return Response.json(pets); |
| 229 | } |
| 230 | |
| 231 | const match = /^\/pets\/(\d+)$/.exec(url.pathname); |
| 232 | if (match && req.method === "GET") { |
| 233 | const pet = pets.find((p) => p.id === Number(match[1])); |
| 234 | if (!pet) return new Response("not found", { status: 404 }); |
| 235 | return Response.json(pet); |
| 236 | } |
| 237 | |
| 238 | return new Response("not found", { status: 404 }); |
| 239 | }, |
| 240 | }); |
| 241 | return { server, origin: `http://127.0.0.1:${server.port}` }; |
| 242 | }; |
no test coverage detected