diff --git a/src/__tests__/utils/request-router.test.ts b/src/__tests__/utils/request-router.test.ts index d8a87e74c..9075669d9 100644 --- a/src/__tests__/utils/request-router.test.ts +++ b/src/__tests__/utils/request-router.test.ts @@ -12,7 +12,7 @@ describe('request-router', () => { const testCases: [string, RequestRouterTarget, string][] = [ // US domain - ['https://app.posthog.com', 'ui', 'https://app.posthog.com'], + ['https://app.posthog.com', 'ui', 'https://us.posthog.com'], ['https://app.posthog.com', 'assets', 'https://us-assets.i.posthog.com'], ['https://app.posthog.com', 'api', 'https://us.i.posthog.com'], // US domain via app domain @@ -26,6 +26,7 @@ describe('request-router', () => { // EU domain ['https://eu.posthog.com', 'ui', 'https://eu.posthog.com'], + ['https://eu.i.posthog.com', 'ui', 'https://eu.posthog.com'], ['https://eu.posthog.com', 'assets', 'https://eu-assets.i.posthog.com'], ['https://eu.posthog.com', 'api', 'https://eu.i.posthog.com'], ['https://eu.i.posthog.com', 'api', 'https://eu.i.posthog.com'], diff --git a/src/utils/request-router.ts b/src/utils/request-router.ts index 9f484cbc8..da635f78b 100644 --- a/src/utils/request-router.ts +++ b/src/utils/request-router.ts @@ -27,14 +27,25 @@ export class RequestRouter { } get apiHost(): string { - return this.instance.config.api_host.trim().replace(/\/$/, '') + const host = this.instance.config.api_host.trim().replace(/\/$/, '') + if (host === 'https://app.posthog.com') { + return 'https://us.i.posthog.com' + } + return host } get uiHost(): string | undefined { - const host = this.instance.config.ui_host?.replace(/\/$/, '') + let host = this.instance.config.ui_host?.replace(/\/$/, '') + + if (!host) { + // No ui_host set, get it from the api_host. But api_host differs + // from the actual UI host, so replace the ingestion subdomain with just posthog.com + host = this.apiHost.replace(`.${ingestionDomain}`, '.posthog.com') + } if (host === 'https://app.posthog.com') { return 'https://us.posthog.com' } + return host } @@ -58,7 +69,7 @@ export class RequestRouter { } if (target === 'ui') { - return (this.uiHost || this.apiHost.replace(`.${ingestionDomain}`, '.posthog.com')) + path + return this.uiHost + path } if (this.region === RequestRouterRegion.CUSTOM) {