(req)
| 234 | port: 0, |
| 235 | hostname: "127.0.0.1", |
| 236 | fetch(req) { |
| 237 | const url = new URL(req.url); |
| 238 | if (url.pathname === "/openapi.json") return Response.json(spec); |
| 239 | |
| 240 | if (url.pathname === "/pets" && req.method === "GET") { |
| 241 | return Response.json(pets); |
| 242 | } |
| 243 | |
| 244 | const match = /^\/pets\/(\d+)$/.exec(url.pathname); |
| 245 | if (match && req.method === "GET") { |
| 246 | const pet = pets.find((p) => p.id === Number(match[1])); |
| 247 | if (!pet) return new Response("not found", { status: 404 }); |
| 248 | return Response.json(pet); |
| 249 | } |
| 250 | |
| 251 | return new Response("not found", { status: 404 }); |
| 252 | }, |
| 253 | }); |
| 254 | return { server, origin: `http://127.0.0.1:${server.port}` }; |
| 255 | }; |
no test coverage detected