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
12 changes: 12 additions & 0 deletions apps/web/src/hostedPairing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,16 @@ describe("hostedPairing", () => {
vi.stubEnv("VITE_HTTP_URL", "https://backend.example.com");
expect(isHostedStaticApp(new URL("https://preview.t3.codes/"))).toBe(false);
});

it("detects hosted channel aliases as static apps", () => {
vi.stubEnv("VITE_HOSTED_APP_URL", "https://app.t3.codes");
vi.stubEnv("VITE_HOSTED_APP_CHANNEL", "nightly");
vi.stubEnv("VITE_HTTP_URL", "");
vi.stubEnv("VITE_WS_URL", "");

expect(isHostedStaticApp(new URL("https://nightly.app.t3.codes/"))).toBe(true);

vi.stubEnv("VITE_HTTP_URL", "https://backend.example.com");
expect(isHostedStaticApp(new URL("https://nightly.app.t3.codes/"))).toBe(false);
});
});
9 changes: 9 additions & 0 deletions apps/web/src/hostedPairing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function configuredBackendUrl(): string {
return import.meta.env.VITE_HTTP_URL?.trim() || import.meta.env.VITE_WS_URL?.trim() || "";
}

function configuredHostedAppChannel(): HostedAppChannel | null {
const channel = import.meta.env.VITE_HOSTED_APP_CHANNEL?.trim().toLowerCase();
return channel === "latest" || channel === "nightly" ? channel : null;
}

function originFromUrl(value: string): string | null {
try {
return new URL(value).origin;
Expand All @@ -31,6 +36,10 @@ export function isHostedStaticApp(url: URL = new URL(window.location.href)): boo
return false;
}

if (configuredHostedAppChannel()) {
return true;
}

const hostedOrigin = originFromUrl(configuredHostedAppUrl());
return hostedOrigin !== null && url.origin === hostedOrigin;
}
Expand Down
Loading