1// Long-lived dev server for the AWS StaticSite. `alchemy dev` spawns it as
2// a `Command.Dev` child inside the provider sidecar and reads the URL it
3// prints. The stress suite pins PORT so the address survives every restart,
4// and reads SITE_MARKER back over `/__dev-env` to prove that a change to
5// `dev.env` actually RESTARTED the child rather than leaving the old one.
6//
7// Plain .mjs so the repo's tsc never type-checks it.
8const port = Number(process.env.PORT ?? 0);
9const server = Bun.serve({
10 port,
11 fetch: async (request) => {
12 const { pathname } = new URL(request.url);
13 if (pathname === "/__dev-env") {
14 return Response.json({
15 marker: process.env.SITE_MARKER ?? null,
16 pid: process.pid,
17 });
18 }
19 const file = Bun.file(
20 `${import.meta.dirname}/site${pathname.endsWith("/") ? `${pathname}index.html` : pathname}`,
21 );
22 return (await file.exists())
23 ? new Response(file)
24 : new Response("not found", { status: 404 });
25 },
26});
27
28console.log(`AWS StaticSite dev server: http://localhost:${server.port}`);