Skip to content

Commit 1b9cf88

Browse files
committed
fix(website): fall back to US PostHog host when env is empty string
GitHub Actions expands an unset `POSTHOG_HOST` secret to "", which passes the nullish check (`??`) and leaves api_host empty. PostHog then falls back to the current origin and sends POST /e/ to cubepi.pages.dev — Cloudflare Pages doesn't accept POST and returns 405, so no events reach PostHog. Switch both the build-time embed and the client init to `||` so an empty string also routes to https://us.i.posthog.com.
1 parent 0055b30 commit 1b9cf88

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

website/docusaurus.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import type { Config } from '@docusaurus/types';
22
import type { Options as ClassicOptions } from '@docusaurus/preset-classic';
33
import { themes as prismThemes } from 'prism-react-renderer';
44

5-
const POSTHOG_KEY = process.env.POSTHOG_KEY ?? '';
6-
const POSTHOG_HOST = process.env.POSTHOG_HOST ?? 'https://us.i.posthog.com';
5+
// Use `||` not `??` here: GitHub Actions expands an unset secret to "" (an
6+
// empty string passes the nullish check, so `??` would leave api_host empty
7+
// and PostHog falls back to the current origin — sending POST /e/ to the
8+
// docs domain and hitting a 405 from Cloudflare Pages).
9+
const POSTHOG_KEY = process.env.POSTHOG_KEY || '';
10+
const POSTHOG_HOST = process.env.POSTHOG_HOST || 'https://us.i.posthog.com';
711
const GIT_SHA = process.env.GITHUB_SHA?.slice(0, 7) ?? 'dev';
812

913
const classicOptions: ClassicOptions = {

website/src/clientModules/posthog.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import posthog from 'posthog-js';
22
import siteConfig from '@generated/docusaurus.config';
33

4-
const key = (siteConfig.customFields?.POSTHOG_KEY as string | undefined) ?? '';
5-
const host = (siteConfig.customFields?.POSTHOG_HOST as string | undefined) ?? 'https://us.i.posthog.com';
4+
// Use `||` not `??`: the build embeds POSTHOG_HOST="" when the secret is
5+
// unset, and we need the empty string to fall back to the US endpoint.
6+
const key = (siteConfig.customFields?.POSTHOG_KEY as string | undefined) || '';
7+
const host = (siteConfig.customFields?.POSTHOG_HOST as string | undefined) || 'https://us.i.posthog.com';
68

79
if (typeof window !== 'undefined' && key) {
810
posthog.init(key, {

0 commit comments

Comments
 (0)