The best way to control Claude Code, Codex and more from any computer or phone
fix(dev): share dev servers on the loopback Vite actually binds (#9324)
Co-authored-by: Julius Marminge <julius@mac.lan> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Julius Marminge committed
Sep 2, 2026 at 20:08 UTC
66419a1d1b80110c9702edae641bddcc2888fc98
2 files changed
+31
-2
scripts/lib/dev-share.test.ts
+20
-1
@@ -27,11 +27,16 @@ const encode = (value: string) => Stream.make(new TextEncoder().encode(value));
27
* test set the outcome of the `off` (pre-clear) and `serve` calls separately —
28
* they are the same subcommand and are told apart by the trailing `off`.
29
*/
30
-const spawnerLayer = (input: { readonly off?: CallResult; readonly serve?: CallResult }) =>
30
+const spawnerLayer = (input: {
31
+ readonly off?: CallResult;
32
+ readonly serve?: CallResult;
33
+ readonly calls?: Array<ReadonlyArray<string>>;
34
+}) =>
35
Layer.succeed(
36
ChildProcessSpawner.ChildProcessSpawner,
37
ChildProcessSpawner.make((command) => {
38
const args = "args" in command ? (command.args as ReadonlyArray<string>) : [];
39
+ input.calls?.push(args);
40
const result: CallResult = args.includes("status")
41
? { exitCode: 0 }
42
: args.includes("off")
@@ -102,6 +107,20 @@ describe("shareDevServer", () => {
107
}),
108
);
109
110
+ // Vite binds `localhost`, which modern Node resolves to `::1` first, so a
111
+ // 127.0.0.1 target would proxy to a loopback nothing listens on.
112
+ it.effect("proxies to the localhost name Vite binds, not 127.0.0.1", () =>
113
+ Effect.gen(function* () {
114
+ const calls: Array<ReadonlyArray<string>> = [];
115
+ yield* shareDevServer({ webPort: 5788 }).pipe(
116
+ Effect.provide(spawnerLayer({ off: { exitCode: 0 }, calls })),
117
+ );
118
+
119
+ const serveCall = calls.find((args) => args.includes("--bg"));
120
+ assert.deepEqual(serveCall, ["serve", "--bg", "--https=5788", "http://localhost:5788"]);
121
+ }),
122
+ );
123
+
124
// The stale-mapping clear runs before serve, so a failure here leaves the
125
// port serving nothing. Saying only "serve failed" would let an operator
126
// assume their previous mapping survived.
scripts/lib/dev-share.ts
+11
-1
@@ -195,7 +195,17 @@ export const shareDevServer = Effect.fn("devShare.shareDevServer")(function* (in
195
});
196
}
197
198
- yield* ensureTailscaleServe({ localPort: input.webPort, servePort: input.webPort }).pipe(
198
+ // Proxy to the hostname Vite binds rather than the package default of
199
+ // 127.0.0.1. Vite listens on `localhost`, which Node 17+ resolves to `::1`
200
+ // first, so it only binds the IPv6 loopback and a 127.0.0.1 target has
201
+ // nothing behind it (tailscale answers 502). Passing `localhost` lets the
202
+ // tailscale proxy resolve it the same way Node did. Not a literal `[::1]`:
203
+ // tailscale rejects that form.
204
+ yield* ensureTailscaleServe({
205
+ localPort: input.webPort,
206
+ servePort: input.webPort,
207
+ localHost: "localhost",
208
+ }).pipe(
209
Effect.mapError((error) => {
210
const explanation = explainCommandFailure(error);
211
return new DevServeFailedError({