The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 21:30 UTC
[codex] fix: preserve localhost preview hosts (#3499)
Co-authored-by: Codex <codex@openai.com>
Wout Stiens committed
Jun 22, 2026 at 19:14 UTC
c1e2408e1f317bba2fbb48a27498b4ae4bef47d8
2 files changed
+19
apps/web/src/browser/browserTargetResolver.test.ts
+8
@@ -47,6 +47,14 @@ describe("browser target resolver", () => {
47
).toBe("http://localhost:3000/app");
48
});
49
50
+ it("preserves localhost server-picker values when the prepared base is 127.0.0.1", async () => {
51
+ readPreparedConnection.mockReturnValue({ httpBaseUrl: "http://127.0.0.1:3773" });
52
+ const { resolveDiscoveredServerUrl } = await import("./browserTargetResolver");
53
+ expect(
54
+ resolveDiscoveredServerUrl(EnvironmentId.make("environment-1"), "localhost:5173/app?x=1#top"),
55
+ ).toBe("http://localhost:5173/app?x=1#top");
56
+ });
57
+
58
it("normalizes public URLs without treating them as environment ports", async () => {
59
const { resolveDiscoveredServerUrl } = await import("./browserTargetResolver");
60
expect(resolveDiscoveredServerUrl(EnvironmentId.make("environment-1"), "example.com/app")).toBe(
apps/web/src/browser/browserTargetResolver.ts
+11
@@ -24,6 +24,11 @@ const isPrivateNetworkHost = (host: string): boolean => {
24
);
25
};
26
27
+const isLocalLoopbackHost = (host: string): boolean => {
28
+ const normalized = host.toLowerCase().replace(/^\[|\]$/g, "");
29
+ return normalized === "localhost" || normalized === "127.0.0.1" || normalized === "::1";
30
+};
31
+
32
export function resolveBrowserNavigationTarget(
33
environmentId: EnvironmentId,
34
target: BrowserNavigationTarget,
@@ -68,6 +73,12 @@ export function resolveDiscoveredServerUrl(environmentId: EnvironmentId, rawUrl:
73
const normalizedUrl = normalizePreviewUrl(rawUrl);
74
const parsed = new URL(normalizedUrl);
75
if (!isLoopbackHost(parsed.hostname)) return normalizedUrl;
76
+ const connection = readPreparedConnection(environmentId);
77
+ if (!connection) throw new Error(`Environment ${environmentId} is not connected.`);
78
+ const environmentUrl = new URL(connection.httpBaseUrl);
79
+ if (parsed.hostname !== "0.0.0.0" && isLocalLoopbackHost(environmentUrl.hostname)) {
80
+ return normalizedUrl;
81
+ }
82
const port = Number(parsed.port || (parsed.protocol === "https:" ? 443 : 80));
83
return resolveBrowserNavigationTarget(environmentId, {
84
kind: "environment-port",