Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions apps/api/src/settings/resolve-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@ describe("resolveConfig Studio environment aliases", () => {
});
});

describe("resolveConfig external database/nats URL detection", () => {
it("treats a bracketed IPv6 loopback DATABASE_URL as local, not external", () => {
const result = resolveConfig(flags, {
DATABASE_URL: "postgres://[::1]:5432/postgres",
});

expect(result.externalDatabaseUrl).toBeNull();
});

it("treats a bracketed IPv6 loopback NATS_URL as local, not external", () => {
const result = resolveConfig(flags, {
NATS_URL: "nats://[::1]:4222",
});

expect(result.externalNatsUrl).toBeNull();
});

it("still treats a genuinely remote host as external", () => {
const result = resolveConfig(flags, {
DATABASE_URL: "postgres://db.example.com:5432/postgres",
});

expect(result.externalDatabaseUrl).toBe(
"postgres://db.example.com:5432/postgres",
);
});
});

describe("resolveConfig NODE_ENV", () => {
it("defaults to development when unset", () => {
const result = resolveConfig(flags, {});
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/settings/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ function externalUrlOrNull(url: string | undefined): string | null {
if (!url) return null;
try {
const parsed = new URL(url);
const host = parsed.hostname;
// `URL#hostname` keeps the brackets for a bracketed IPv6 host (e.g.
// "[::1]"), so strip them before comparing against the bare loopback form.
const host = parsed.hostname.replace(/^\[|\]$/g, "");
if (host === "localhost" || host === "127.0.0.1" || host === "::1") {
return null;
}
Expand Down
Loading