diff --git a/site/src/contexts/ProxyContext.test.ts b/site/src/contexts/ProxyContext.test.ts index 5442c3f3c2e35..a94ebbec22081 100644 --- a/site/src/contexts/ProxyContext.test.ts +++ b/site/src/contexts/ProxyContext.test.ts @@ -2,6 +2,7 @@ import { MockPrimaryWorkspaceProxy, MockWorkspaceProxies, MockHealthyWildWorkspaceProxy, + MockUnhealthyWildWorkspaceProxy, } from "testHelpers/entities" import { getPreferredProxy } from "./ProxyContext" @@ -38,6 +39,14 @@ describe("ProxyContextGetURLs", () => { "", MockPrimaryWorkspaceProxy.wildcard_hostname, ], + // Primary is the default if the selected is unhealthy + [ + "unhealthy selection", + MockWorkspaceProxies, + MockUnhealthyWildWorkspaceProxy, + "", + MockPrimaryWorkspaceProxy.wildcard_hostname, + ], // This should never happen, when there is no primary ["no primary", [MockHealthyWildWorkspaceProxy], undefined, "", ""], ])( diff --git a/site/src/contexts/ProxyContext.tsx b/site/src/contexts/ProxyContext.tsx index c89ae309aecc8..87eeb364e160e 100644 --- a/site/src/contexts/ProxyContext.tsx +++ b/site/src/contexts/ProxyContext.tsx @@ -149,8 +149,8 @@ export const getPreferredProxy = ( (proxy) => selectedProxy && proxy.id === selectedProxy.id, ) - if (!selectedProxy) { - // If no proxy is selected, default to the primary proxy. + // If no proxy is selected, or the selected proxy is unhealthy default to the primary proxy. + if (!selectedProxy || !selectedProxy.healthy) { selectedProxy = proxies.find((proxy) => proxy.name === "primary") } diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index 3405b6a0cfcb5..c9458a79af61c 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -88,18 +88,20 @@ export const MockHealthyWildWorkspaceProxy: TypesGen.Region = { wildcard_hostname: "*.external.com", } +export const MockUnhealthyWildWorkspaceProxy: TypesGen.Region = { + id: "8444931c-0247-4171-842a-569d9f9cbadb", + name: "unhealthy", + display_name: "Unhealthy", + icon_url: "/emojis/1f92e.png", + healthy: false, + path_app_url: "https://unhealthy.coder.com", + wildcard_hostname: "*unhealthy..coder.com", +} + export const MockWorkspaceProxies: TypesGen.Region[] = [ MockPrimaryWorkspaceProxy, MockHealthyWildWorkspaceProxy, - { - id: "8444931c-0247-4171-842a-569d9f9cbadb", - name: "unhealthy", - display_name: "Unhealthy", - icon_url: "/emojis/1f92e.png", - healthy: false, - path_app_url: "https://unhealthy.coder.com", - wildcard_hostname: "*unhealthy..coder.com", - }, + MockUnhealthyWildWorkspaceProxy, { id: "26e84c16-db24-4636-a62d-aa1a4232b858", name: "nowildcard",