Skip to content

Commit 9aeeade

Browse files
author
Julius Marminge
committed
fix hosted channel bootstrap
1 parent 6efdf67 commit 9aeeade

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

apps/web/src/hostedPairing.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,16 @@ describe("hostedPairing", () => {
7979
vi.stubEnv("VITE_HTTP_URL", "https://backend.example.com");
8080
expect(isHostedStaticApp(new URL("https://preview.t3.codes/"))).toBe(false);
8181
});
82+
83+
it("detects hosted channel aliases as static apps", () => {
84+
vi.stubEnv("VITE_HOSTED_APP_URL", "https://app.t3.codes");
85+
vi.stubEnv("VITE_HOSTED_APP_CHANNEL", "nightly");
86+
vi.stubEnv("VITE_HTTP_URL", "");
87+
vi.stubEnv("VITE_WS_URL", "");
88+
89+
expect(isHostedStaticApp(new URL("https://nightly.app.t3.codes/"))).toBe(true);
90+
91+
vi.stubEnv("VITE_HTTP_URL", "https://backend.example.com");
92+
expect(isHostedStaticApp(new URL("https://nightly.app.t3.codes/"))).toBe(false);
93+
});
8294
});

apps/web/src/hostedPairing.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ function configuredBackendUrl(): string {
1818
return import.meta.env.VITE_HTTP_URL?.trim() || import.meta.env.VITE_WS_URL?.trim() || "";
1919
}
2020

21+
function configuredHostedAppChannel(): HostedAppChannel | null {
22+
const channel = import.meta.env.VITE_HOSTED_APP_CHANNEL?.trim().toLowerCase();
23+
return channel === "latest" || channel === "nightly" ? channel : null;
24+
}
25+
2126
function originFromUrl(value: string): string | null {
2227
try {
2328
return new URL(value).origin;
@@ -31,6 +36,10 @@ export function isHostedStaticApp(url: URL = new URL(window.location.href)): boo
3136
return false;
3237
}
3338

39+
if (configuredHostedAppChannel()) {
40+
return true;
41+
}
42+
3443
const hostedOrigin = originFromUrl(configuredHostedAppUrl());
3544
return hostedOrigin !== null && url.origin === hostedOrigin;
3645
}

0 commit comments

Comments
 (0)