| 1 | // Minimal long-lived dev server for the StaticSite fixture: serves ./src |
| 2 | // over HTTP on an ephemeral port and prints its own localhost URL, which |
| 3 | // `Command.Dev` extracts from stdout and surfaces as the site's dev `url`. |
| 4 | // |
| 5 | // `/__dev-env` echoes the DEV_MARKER environment variable so tests can |
| 6 | // prove that `dev.env` reached the spawned child process. |
| 7 | // |
| 8 | // Plain .mjs (not .ts) so the test project's tsc never type-checks it — |
| 9 | // it only ever runs under bun as a fixture child process. |
| 10 | const server = Bun.serve({ |
| 11 | port: 0, |
| 12 | fetch: async (request) => { |
| 13 | const { pathname } = new URL(request.url); |
| 14 | if (pathname === "/__dev-env") { |
| 15 | return Response.json({ marker: process.env.DEV_MARKER ?? null }); |
| 16 | } |
| 17 | const file = Bun.file( |
| 18 | `${process.cwd()}/src${pathname === "/" ? "/index.html" : pathname}`, |
| 19 | ); |
| 20 | return (await file.exists()) |
| 21 | ? new Response(file) |
| 22 | : new Response("not found", { status: 404 }); |
| 23 | }, |
| 24 | }); |
| 25 | |
| 26 | console.log(`StaticSite fixture dev server: http://localhost:${server.port}`); |