Skip to content

Commit c90ddf7

Browse files
committed
fix: read actual bound port from HttpServer before configuring Tailscale Serve
When config.port is 0 (OS-assigned), the real port is only known after the HTTP server binds. The tailscaleServeLayer now reads the actual bound port from HttpServer.address instead of using config.port directly, preventing Tailscale Serve from being configured to proxy to port 0.
1 parent 20edab7 commit c90ddf7

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

apps/server/src/server.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,24 @@ export const makeServerLayer = Layer.unwrap(
309309
);
310310
const tailscaleServeLayer = config.tailscaleServeEnabled
311311
? Layer.effectDiscard(
312-
ensureTailscaleServe({
313-
localPort: config.port,
314-
servePort: config.tailscaleServePort,
315-
localHost: "127.0.0.1",
312+
Effect.gen(function* () {
313+
const server = yield* HttpServer.HttpServer;
314+
const address = server.address;
315+
const localPort =
316+
typeof address !== "string" && "port" in address ? address.port : config.port;
317+
yield* ensureTailscaleServe({
318+
localPort,
319+
servePort: config.tailscaleServePort,
320+
localHost: "127.0.0.1",
321+
}).pipe(
322+
Effect.tap(() =>
323+
Effect.logInfo("Tailscale Serve configured", {
324+
localPort,
325+
servePort: config.tailscaleServePort,
326+
}),
327+
),
328+
);
316329
}).pipe(
317-
Effect.tap(() =>
318-
Effect.logInfo("Tailscale Serve configured", {
319-
localPort: config.port,
320-
servePort: config.tailscaleServePort,
321-
}),
322-
),
323330
Effect.catch((cause) =>
324331
Effect.logWarning("Failed to configure Tailscale Serve", {
325332
cause,

0 commit comments

Comments
 (0)