Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Safely add livestream host #28727

Merged
merged 18 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
6 changes: 5 additions & 1 deletion frontend/src/lib/utils/apiHost.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAppContext } from './getAppContext'

export function apiHostOrigin(): string {
const appOrigin = window.location.origin
if (appOrigin === 'https://us.posthog.com') {
Expand All @@ -10,6 +12,8 @@ export function apiHostOrigin(): string {

export function liveEventsHostOrigin(): string | null {
const appOrigin = window.location.origin
const appContext = getAppContext()

if (appOrigin === 'https://us.posthog.com') {
return 'https://live.us.posthog.com'
} else if (appOrigin === 'https://eu.posthog.com') {
Expand All @@ -20,5 +24,5 @@ export function liveEventsHostOrigin(): string | null {
return 'http://localhost:6006'
}

return 'http://localhost:8666'
return appContext?.livestream_host || 'http://localhost:8666'
}
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3470,6 +3470,7 @@ export interface AppContext {
year_in_hog_url?: string
/** Support flow aid: a staff-only list of users who may be impersonated to access this resource. */
suggested_users_with_access?: UserBasicType[]
livestream_host?: string
}

export type StoredMetricMathOperations = 'max' | 'min' | 'sum'
Expand Down
3 changes: 3 additions & 0 deletions posthog/settings/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,6 @@ def static_varies_origin(headers, path, url):
# Teams allowed to modify transformation code (comma-separated list of team IDs),
# keep in sync with client-side feature flag HOG_TRANSFORMATIONS_CUSTOM_HOG_ENABLED
HOG_TRANSFORMATIONS_CUSTOM_ENABLED_TEAMS = get_list(os.getenv("HOG_TRANSFORMATIONS_CUSTOM_ENABLED_TEAMS", ""))

# Passed to the frontend for the web app to know where to connect to
LIVESTREAM_HOST = get_from_env("LIVESTREAM_HOST", "")
4 changes: 2 additions & 2 deletions posthog/test/__snapshots__/test_feature_flag.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@
FROM "posthog_cohort"
INNER JOIN "posthog_team" ON ("posthog_cohort"."team_id" = "posthog_team"."id")
WHERE (NOT "posthog_cohort"."deleted"
AND "posthog_team"."project_id" = 525)
AND "posthog_team"."project_id" = 528)
'''
# ---
# name: TestFeatureFlagMatcher.test_numeric_operator_with_cohorts_and_nested_cohorts.1
Expand Down Expand Up @@ -2115,7 +2115,7 @@
"posthog_grouptypemapping"."name_singular",
"posthog_grouptypemapping"."name_plural"
FROM "posthog_grouptypemapping"
WHERE "posthog_grouptypemapping"."project_id" = 525
WHERE "posthog_grouptypemapping"."project_id" = 528
'''
# ---
# name: TestFeatureFlagMatcher.test_numeric_operator_with_groups_and_person_flags.1
Expand Down
1 change: 1 addition & 0 deletions posthog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def render_template(
"switched_team": getattr(request, "switched_team", None),
"suggested_users_with_access": getattr(request, "suggested_users_with_access", None),
"commit_sha": context["git_rev"],
"livestream_host": settings.LIVESTREAM_HOST,
**posthog_app_context,
}

Expand Down
Loading