Skip to content

Commit 9a68fea

Browse files
Julius Marmingeclaude
andcommitted
fix(dev): share dev servers on the loopback Vite actually binds
`vp run dev --share` registered a `tailscale serve` rule targeting `http://127.0.0.1:<webPort>`, but Vite binds `localhost`, which Node 17+ resolves to `::1` first, so only the IPv6 loopback is listening and the tailnet URL returned a 502. Pass `localHost: "localhost"` from the dev-share path so the tailscale proxy resolves the same name Vite bound. The server's own `--tailscale-serve` path is untouched: it binds 127.0.0.1 explicitly. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent b9b1b8f commit 9a68fea

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎scripts/lib/dev-share.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ const encode = (value: string) => Stream.make(new TextEncoder().encode(value));
2727
* test set the outcome of the `off` (pre-clear) and `serve` calls separately —
2828
* they are the same subcommand and are told apart by the trailing `off`.
2929
*/
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+
}) =>
3135
Layer.succeed(
3236
ChildProcessSpawner.ChildProcessSpawner,
3337
ChildProcessSpawner.make((command) => {
3438
const args = "args" in command ? (command.args as ReadonlyArray<string>) : [];
39+
input.calls?.push(args);
3540
const result: CallResult = args.includes("status")
3641
? { exitCode: 0 }
3742
: args.includes("off")
@@ -102,6 +107,20 @@ describe("shareDevServer", () => {
102107
}),
103108
);
104109

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+
105124
// The stale-mapping clear runs before serve, so a failure here leaves the
106125
// port serving nothing. Saying only "serve failed" would let an operator
107126
// assume their previous mapping survived.

‎scripts/lib/dev-share.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,17 @@ export const shareDevServer = Effect.fn("devShare.shareDevServer")(function* (in
195195
});
196196
}
197197

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(
199209
Effect.mapError((error) => {
200210
const explanation = explainCommandFailure(error);
201211
return new DevServeFailedError({

0 commit comments

Comments
 (0)