The best way to control Claude Code, Codex and more from any computer or phone

main
cjs 23 lines 831 Bytes
Raw
1 // Fixture for Command.Dev `port` tests. Writes its PID + marker to PID_FILE,
2 // then listens on `PORT` without printing anything and stays alive.
3 //
4 // `LISTEN_DELAY_MS` -> how long to wait before listening (default 0). Lets the
5 // test show readiness waits for the port, not for output or a deadline.
6 const fs = require("node:fs");
7 const net = require("node:net");
8
9 const pidFile = process.env.PID_FILE;
10 const marker = process.env.MARKER ?? "default";
11 const port = Number(process.env.PORT);
12
13 if (!pidFile || !port) {
14 console.error("port-server.cjs: PID_FILE and PORT env vars are required");
15 process.exit(1);
16 }
17
18 fs.writeFileSync(pidFile, JSON.stringify({ pid: process.pid, marker }));
19
20 setTimeout(
21 () => net.createServer((socket) => socket.end()).listen(port, "127.0.0.1"),
22 Number(process.env.LISTEN_DELAY_MS ?? 0),
23 );