Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/cli/src/legacy/commands/start/start.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
legacyIsEncryptedSecret,
} from "../../shared/legacy-vault-decrypt.ts";
import { legacyParseGoDuration } from "../../shared/legacy-go-duration.ts";
import { legacyConfigureLoopbackProxyBypass } from "../../shared/legacy-hostname.ts";
import {
legacyCliProjectFilterValue,
legacyServiceContainerIds,
Expand Down Expand Up @@ -1979,6 +1980,8 @@ export const legacyStart = Effect.fn("legacy.start")(function* (flags: LegacySta
projectRef: "",
config: effectiveLocalStorageConfig,
});
// Keep the synthetic value out of project dotenv resolution and container environments.
legacyConfigureLoopbackProxyBypass();
Comment thread
7ttp marked this conversation as resolved.
Comment thread
7ttp marked this conversation as resolved.
const healthResult = yield* legacyWaitForHealthyServices(spawner, [...started.keys()], {
postgrest: postgrestGateway,
edgeRuntime: edgeRuntimeGateway,
Expand Down
8 changes: 8 additions & 0 deletions apps/cli/src/legacy/shared/legacy-hostname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { homedir } from "node:os";
import { join } from "node:path";

const LOCAL_HOST = "127.0.0.1";
const LOOPBACK_NO_PROXY = `localhost,${LOCAL_HOST},[::1]`;

/** Docker CLI's reserved "no context store entry" name (`docker/cli` `cli/command/cli.go`'s `DefaultContextName`). */
const DEFAULT_CONTEXT_NAME = "default";
Expand Down Expand Up @@ -141,3 +142,10 @@ export function legacyGetHostname(): string {
}
return LOCAL_HOST;
}

/** Keeps Bun from proxying the legacy CLI's loopback HTTP requests. */
export function legacyConfigureLoopbackProxyBypass(env: NodeJS.ProcessEnv = process.env): void {
const key = (env["no_proxy"]?.length ?? 0) > 0 ? "no_proxy" : "NO_PROXY";
Comment thread
7ttp marked this conversation as resolved.
const current = env[key];
env[key] = current ? `${current},${LOOPBACK_NO_PROXY}` : LOOPBACK_NO_PROXY;
}
32 changes: 31 additions & 1 deletion apps/cli/src/legacy/shared/legacy-hostname.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";

import { legacyGetHostname } from "./legacy-hostname.ts";
import { legacyConfigureLoopbackProxyBypass, legacyGetHostname } from "./legacy-hostname.ts";

const LOOPBACK_NO_PROXY = "localhost,127.0.0.1,[::1]";

function withEnv<T>(entries: Record<string, string | undefined>, run: () => T): T {
const previous: Record<string, string | undefined> = {};
Expand Down Expand Up @@ -186,3 +188,31 @@ describe("legacyGetHostname", () => {
});
});
});

describe("legacyConfigureLoopbackProxyBypass", () => {
it.each([
["sets NO_PROXY when neither spelling is configured", {}, { NO_PROXY: LOOPBACK_NO_PROXY }],
[
"preserves an existing NO_PROXY value",
{ NO_PROXY: "example.com" },
{ NO_PROXY: `example.com,${LOOPBACK_NO_PROXY}` },
],
[
"updates the non-empty lowercase value preferred by Bun",
{ NO_PROXY: "uppercase.example", no_proxy: "lowercase.example" },
{
NO_PROXY: "uppercase.example",
no_proxy: `lowercase.example,${LOOPBACK_NO_PROXY}`,
},
],
[
"falls back to NO_PROXY when lowercase no_proxy is empty",
{ NO_PROXY: "example.com", no_proxy: "" },
{ NO_PROXY: `example.com,${LOOPBACK_NO_PROXY}`, no_proxy: "" },
],
])("%s", (_name, env, expected) => {
legacyConfigureLoopbackProxyBypass(env);

expect(env).toEqual(expected);
});
});
Loading