From 7ec8ce2a5622a7dedaa309d5c0a8f58723cc4dc6 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Thu, 28 Sep 2023 12:56:53 +1000 Subject: [PATCH] feat: add posthog reverse proxy (#449) --- apps/marketing/next.config.js | 8 ++++++++ apps/web/next.config.js | 8 ++++++++ packages/lib/constants/feature-flags.ts | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/marketing/next.config.js b/apps/marketing/next.config.js index e74f7d545..aeb06bdfd 100644 --- a/apps/marketing/next.config.js +++ b/apps/marketing/next.config.js @@ -56,6 +56,14 @@ const config = { }, ]; }, + async rewrites() { + return [ + { + source: '/ingest/:path*', + destination: 'https://eu.posthog.com/:path*', + }, + ]; + }, }; module.exports = withContentlayer(config); diff --git a/apps/web/next.config.js b/apps/web/next.config.js index c4359060b..b9e5d2517 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -29,6 +29,14 @@ const config = { transform: 'lucide-react/dist/esm/icons/{{ kebabCase member }}', }, }, + async rewrites() { + return [ + { + source: '/ingest/:path*', + destination: 'https://eu.posthog.com/:path*', + }, + ]; + }, }; module.exports = config; diff --git a/packages/lib/constants/feature-flags.ts b/packages/lib/constants/feature-flags.ts index e23f59eba..e972b47c2 100644 --- a/packages/lib/constants/feature-flags.ts +++ b/packages/lib/constants/feature-flags.ts @@ -1,3 +1,5 @@ +import { APP_BASE_URL } from './app'; + /** * The flag name for global session recording feature flag. */ @@ -23,7 +25,7 @@ export const LOCAL_FEATURE_FLAGS: Record = { */ export function extractPostHogConfig(): { key: string; host: string } | null { const postHogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY; - const postHogHost = process.env.NEXT_PUBLIC_POSTHOG_HOST; + const postHogHost = `${APP_BASE_URL}/ingest`; if (!postHogKey || !postHogHost) { return null;