Skip to content

Commit

Permalink
feat: default api host to new ingestion domain (#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
raquelmsmith committed Aug 26, 2024
1 parent 3379ba1 commit ba3ba9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/__tests__/utils/request-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'],
Expand Down
17 changes: 14 additions & 3 deletions src/utils/request-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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) {
Expand Down

0 comments on commit ba3ba9f

Please sign in to comment.