Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Feb 5, 2024
1 parent 5c51ce6 commit 493f61c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/utils/request-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ describe('request-router', () => {
// US domain
['https://app.posthog.com', 'ui', 'https://app.posthog.com'],
['https://app.posthog.com', 'capture_events', 'https://us-c.i.posthog.com'],
['https://app.posthog.com', 'capture_replay', 'https://us-s.i.posthog.com'],
['https://app.posthog.com', 'capture_recordings', 'https://us-s.i.posthog.com'],
['https://app.posthog.com', 'decide', 'https://us-d.i.posthog.com'],
['https://app.posthog.com', 'assets', 'https://us.i.posthog.com'],
// US domain via app domain
['https://us.posthog.com', 'ui', 'https://us.posthog.com'],
['https://us.posthog.com', 'capture_events', 'https://us-c.i.posthog.com'],
['https://us.posthog.com', 'capture_replay', 'https://us-s.i.posthog.com'],
['https://us.posthog.com', 'capture_recordings', 'https://us-s.i.posthog.com'],
['https://us.posthog.com', 'decide', 'https://us-d.i.posthog.com'],
['https://us.posthog.com', 'assets', 'https://us.i.posthog.com'],

// EU domain
['https://eu.posthog.com', 'ui', 'https://eu.posthog.com'],
['https://eu.posthog.com', 'capture_events', 'https://eu-c.i.posthog.com'],
['https://eu.posthog.com', 'capture_replay', 'https://eu-s.i.posthog.com'],
['https://eu.posthog.com', 'capture_recordings', 'https://eu-s.i.posthog.com'],
['https://eu.posthog.com', 'decide', 'https://eu-d.i.posthog.com'],
['https://eu.posthog.com', 'assets', 'https://eu.i.posthog.com'],

// custom domain
['https://my-custom-domain.com', 'ui', 'https://my-custom-domain.com'],
['https://my-custom-domain.com', 'capture_events', 'https://my-custom-domain.com'],
['https://my-custom-domain.com', 'capture_replay', 'https://my-custom-domain.com'],
['https://my-custom-domain.com', 'capture_recordings', 'https://my-custom-domain.com'],
['https://my-custom-domain.com', 'decide', 'https://my-custom-domain.com'],
['https://my-custom-domain.com', 'assets', 'https://my-custom-domain.com'],
]
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class PostHogFeatureFlags {
if (!existing_early_access_features || force_reload) {
this.instance._send_request(
this.instance.requestRouter.endpointFor(
'assets',
'api',
`/api/early_access_features/?token=${this.instance.config.token}`
),
{},
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class PostHogSurveys {
const existingSurveys = this.instance.get_property(SURVEYS)
if (!existingSurveys || forceReload) {
this.instance._send_request(
this.instance.requestRouter.endpointFor('assets', `/api/surveys/?token=${this.instance.config.token}`),
this.instance.requestRouter.endpointFor('api', `/api/surveys/?token=${this.instance.config.token}`),
{},
{ method: 'GET' },
(response) => {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export interface PostHogConfig {
disable_scroll_properties?: boolean
// Let the pageview scroll stats use a custom css selector for the root element, e.g. `main`
scroll_root_selector?: string | string[]
__preview_ingestion_endpoints?: boolean
}

export interface OptInOutCapturingOptions {
Expand Down Expand Up @@ -273,6 +274,7 @@ export interface DecideResponse {
toolbarVersion: 'toolbar' /** @deprecated, moved to toolbarParams */
isAuthenticated: boolean
siteApps: { id: number; url: string }[]
__preview_ingestion_endpoints?: boolean
}

export type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>) => void
Expand Down
13 changes: 8 additions & 5 deletions src/utils/request-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ export enum RequestRouterRegion {
CUSTOM = 'custom',
}

export type RequestRouterTarget = 'ui' | 'capture_events' | 'capture_replay' | 'decide' | 'assets'
export type RequestRouterTarget = 'ui' | 'capture_events' | 'capture_recordings' | 'decide' | 'assets' | 'api'

// DEV NOTES:
// app.posthog.com should become us.i.posthog.com as the base host
// specific endpoints become us-c.i.posthog.com or us-s.i.posthog.com depending on the use case

// TODO:
// - Add override from the decide endpoint

export class RequestRouter {
instance: PostHog

Expand Down Expand Up @@ -60,14 +63,14 @@ export class RequestRouter {
switch (target) {
case 'capture_events':
return `https://${this.region}-c.${suffix}`
case 'capture_replay':
case 'capture_recordings':
return `https://${this.region}-s.${suffix}`
case 'decide':
return `https://${this.region}-d.${suffix}`
case 'assets':
default:
// TODO: Is this right? This would be all things like surveys / early access requests
return `https://${this.region}.${suffix}`
return `https://${this.region}-assets.${suffix}`
case 'api':
return `https://${this.region}-api.${suffix}`
}
}
}

0 comments on commit 493f61c

Please sign in to comment.