Skip to content

Commit 2de065b

Browse files
fix(tailscale): preserve loopback default in direct discovery
1 parent 3f3bcf8 commit 2de065b

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎apps/server/src/environment/DirectEndpoints.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,58 @@ const resolveWithServe = (probeStatus: number) =>
289289
);
290290

291291
describe("DirectEndpoints Tailscale Serve", () => {
292+
for (const probeState of ["healthy", "failed", "timeout"] as const) {
293+
effectIt.effect(`keeps an unspecified listener loopback when HTTPS is ${probeState}`, () =>
294+
Effect.gen(function* () {
295+
using _interfaces = vi
296+
.spyOn(NodeOS, "networkInterfaces")
297+
.mockReturnValue({ tailscale0: vpnInterface("100.64.1.2") });
298+
const probeStarted = yield* Deferred.make<void>();
299+
const service = yield* DirectEndpoints.make.pipe(
300+
Effect.provide(
301+
Layer.mergeAll(
302+
Layer.effect(
303+
ServerConfig.ServerConfig,
304+
Effect.map(ServerConfig.ServerConfig, (config) => ({ ...config, host: undefined })),
305+
).pipe(Layer.provide(layerServeConfig())),
306+
layerTailscaleUp,
307+
Layer.succeed(
308+
HttpClient.HttpClient,
309+
HttpClient.make((request) =>
310+
Deferred.succeed(probeStarted, undefined).pipe(
311+
Effect.andThen(
312+
probeState === "timeout"
313+
? Effect.never
314+
: Effect.succeed(
315+
HttpClientResponse.fromWeb(
316+
request,
317+
new Response(null, { status: probeState === "healthy" ? 200 : 502 }),
318+
),
319+
),
320+
),
321+
),
322+
),
323+
),
324+
),
325+
),
326+
);
327+
const resolving = yield* Effect.forkScoped(service.resolve());
328+
yield* Deferred.await(probeStarted);
329+
if (probeState === "timeout") {
330+
expect(yield* service.resolveAvailable()).toEqual([]);
331+
yield* TestClock.adjust("3 seconds");
332+
}
333+
const endpoints = yield* Fiber.join(resolving);
334+
expect(endpoints).toEqual(
335+
probeState === "healthy"
336+
? [{ kind: "tailnet", httpBaseUrl: "https://bb-1.tail1234.ts.net/" }]
337+
: [],
338+
);
339+
expect(yield* service.resolveAvailable()).toEqual(endpoints);
340+
}).pipe(Effect.scoped),
341+
);
342+
}
343+
292344
effectIt.effect("lists the tailnet name once Serve answers for this server", () =>
293345
Effect.gen(function* () {
294346
expect(yield* resolveWithServe(200)).toEqual([

‎packages/tailscale/src/tailscale.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export function buildTailscaleDirectBaseUrl(input: {
410410
)
411411
)
412412
return null;
413-
const host = input.host === undefined ? "::" : normalizeIpAddress(input.host);
413+
const host = normalizeIpAddress(input.host ?? "127.0.0.1");
414414
if (host === null) return null;
415415
const selfAddresses = new Set(
416416
[...status.tailnetIpv4Addresses, ...status.tailnetIpv6Addresses].map(normalizeIpAddress),

0 commit comments

Comments
 (0)