diff --git a/library/agent/getAPIURL.ts b/library/agent/getAPIURL.ts index ae1de5ac0..56162e6d2 100644 --- a/library/agent/getAPIURL.ts +++ b/library/agent/getAPIURL.ts @@ -1,23 +1,9 @@ -import { extractRegionFromToken } from "./extractRegionFromToken"; +import { getDefaultZenAPIURL } from "./getDefaultZenAPIURL"; export function getAPIURL() { if (process.env.AIKIDO_ENDPOINT) { return new URL(process.env.AIKIDO_ENDPOINT); } - const region = extractRegionFromToken(process.env.AIKIDO_TOKEN || ""); - - if (region === "US") { - return new URL("https://guard.us.aikido.dev"); - } - - if (region === "ME") { - return new URL("https://guard.me.aikido.dev"); - } - - if (region === "AU") { - return new URL("https://guard.au.aikido.dev"); - } - - return new URL("https://guard.aikido.dev"); + return getDefaultZenAPIURL(); } diff --git a/library/agent/getDefaultZenAPIURL.ts b/library/agent/getDefaultZenAPIURL.ts new file mode 100644 index 000000000..80b4306f8 --- /dev/null +++ b/library/agent/getDefaultZenAPIURL.ts @@ -0,0 +1,19 @@ +import { extractRegionFromToken } from "./extractRegionFromToken"; + +export function getDefaultZenAPIURL() { + const region = extractRegionFromToken(process.env.AIKIDO_TOKEN || ""); + + if (region === "US") { + return new URL("https://guard.us.aikido.dev"); + } + + if (region === "ME") { + return new URL("https://guard.me.aikido.dev"); + } + + if (region === "AU") { + return new URL("https://guard.au.aikido.dev"); + } + + return new URL("https://guard.aikido.dev"); +} diff --git a/library/agent/realtime/getRealtimeURL.ts b/library/agent/realtime/getRealtimeURL.ts index 6f2cc465d..3d8eaa7a4 100644 --- a/library/agent/realtime/getRealtimeURL.ts +++ b/library/agent/realtime/getRealtimeURL.ts @@ -1,7 +1,9 @@ +import { getDefaultZenAPIURL } from "../getDefaultZenAPIURL"; + export function getRealtimeURL() { if (process.env.AIKIDO_REALTIME_ENDPOINT) { return new URL(process.env.AIKIDO_REALTIME_ENDPOINT); } - return new URL("https://runtime.aikido.dev"); + return getDefaultZenAPIURL(); } diff --git a/library/agent/realtime/pollForChanges.test.ts b/library/agent/realtime/pollForChanges.test.ts index abfe9be68..18f94dca6 100644 --- a/library/agent/realtime/pollForChanges.test.ts +++ b/library/agent/realtime/pollForChanges.test.ts @@ -35,7 +35,7 @@ t.test("it checks for config updates", async () => { method: params.method, }); - if (params.url.hostname.startsWith("runtime")) { + if (params.url.pathname === "/config") { return { body: JSON.stringify({ configUpdatedAt: configUpdatedAt, @@ -44,7 +44,7 @@ t.test("it checks for config updates", async () => { }; } - if (params.url.hostname.startsWith("guard")) { + if (params.url.pathname === "/api/runtime/config") { return { body: JSON.stringify({ endpoints: [], @@ -55,7 +55,7 @@ t.test("it checks for config updates", async () => { }; } - throw new Error(`Unknown hostname: ${params.url.hostname}`); + throw new Error(`Unknown path: ${params.url.pathname}`); }; }); @@ -78,7 +78,7 @@ t.test("it checks for config updates", async () => { t.same(configUpdates, []); t.same(calls, [ { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, ]); @@ -95,11 +95,11 @@ t.test("it checks for config updates", async () => { ]); t.same(calls, [ { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, { @@ -119,11 +119,11 @@ t.test("it checks for config updates", async () => { ]); t.same(calls, [ { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, { @@ -131,7 +131,7 @@ t.test("it checks for config updates", async () => { method: "GET", }, { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, ]); @@ -153,11 +153,11 @@ t.test("it checks for config updates", async () => { ]); t.same(calls, [ { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, { @@ -165,11 +165,11 @@ t.test("it checks for config updates", async () => { method: "GET", }, { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, { - url: "https://runtime.aikido.dev/config", + url: "https://guard.aikido.dev/config", method: "GET", }, {