From 7724fd847d45cc5c731c4e05cf47ef4790090435 Mon Sep 17 00:00:00 2001 From: Yidir Date: Sat, 18 Jan 2025 06:35:52 -0500 Subject: [PATCH 1/3] fix(livestream): Enable custom livestream host (#26106) Signed-off-by: Yidir --- frontend/src/lib/utils/apiHost.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/lib/utils/apiHost.ts b/frontend/src/lib/utils/apiHost.ts index 52406be14dc26..12869d4e05d8b 100644 --- a/frontend/src/lib/utils/apiHost.ts +++ b/frontend/src/lib/utils/apiHost.ts @@ -17,5 +17,5 @@ export function liveEventsHostOrigin(): string | null { } else if (appOrigin === 'https://app.dev.posthog.dev') { return 'https://live.dev.posthog.dev' } - return 'http://localhost:8666' + return process.env.LIVESTREAM_HOST || 'http://localhost:8666' } From 130a6322b8a7fc2359b71824ef7bf78682023777 Mon Sep 17 00:00:00 2001 From: Yidir Date: Fri, 24 Jan 2025 01:30:39 -0500 Subject: [PATCH 2/3] Add livestream_host to app context Signed-off-by: Yidir --- frontend/src/lib/utils/apiHost.ts | 6 +++++- frontend/src/types.ts | 1 + posthog/utils.py | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/utils/apiHost.ts b/frontend/src/lib/utils/apiHost.ts index 12869d4e05d8b..8b072bf2475a9 100644 --- a/frontend/src/lib/utils/apiHost.ts +++ b/frontend/src/lib/utils/apiHost.ts @@ -1,3 +1,5 @@ +import { getAppContext } from './getAppContext'; + export function apiHostOrigin(): string { const appOrigin = window.location.origin if (appOrigin === 'https://us.posthog.com') { @@ -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') { @@ -17,5 +21,5 @@ export function liveEventsHostOrigin(): string | null { } else if (appOrigin === 'https://app.dev.posthog.dev') { return 'https://live.dev.posthog.dev' } - return process.env.LIVESTREAM_HOST || 'http://localhost:8666' + return appContext?.livestream_host || 'http://localhost:8666' } diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 19998559d505d..dfc4533cbe032 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -3483,6 +3483,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' diff --git a/posthog/utils.py b/posthog/utils.py index 4daec7bec89a8..96f23f84bae8e 100644 --- a/posthog/utils.py +++ b/posthog/utils.py @@ -349,6 +349,8 @@ def render_template( context["sentry_environment"] = sentry_environment if stripe_public_key := os.environ.get("STRIPE_PUBLIC_KEY"): context["stripe_public_key"] = stripe_public_key + if livestream_host := os.environ.get("LIVESTREAM_HOST"): + context["livestream_host"] = livestream_host context["git_rev"] = get_git_commit_short() # Include commit in prod for the `console.info()` message if settings.DEBUG and not settings.TEST: From abe8cad9682d04f20c873c37f215c6d91d6dc369 Mon Sep 17 00:00:00 2001 From: Yidir Date: Fri, 24 Jan 2025 04:55:21 -0500 Subject: [PATCH 3/3] Add livestream_host to posthog_app_context Signed-off-by: Yidir --- posthog/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/posthog/utils.py b/posthog/utils.py index 96f23f84bae8e..97243429bbeef 100644 --- a/posthog/utils.py +++ b/posthog/utils.py @@ -413,6 +413,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": context["livestream_host"], **posthog_app_context, }