History

marketing: source PostHog key from wrangler vars (match cloud)

Add PUBLIC_POSTHOG_KEY to apps/marketing/wrangler.toml [vars] and bridge the PUBLIC_ vars into the build in astro.config.mjs via wrangler unstable_readConfig, mirroring how apps/cloud reads its wrangler.jsonc vars. The public project key is now the committed single source of truth, inlined into the client bundle at build (and also a runtime binding), instead of a gitignored .env.

Rhys Sullivan committed 4 months ago

Commit 0f53b5b1 parent b74c3652 files · +27 −0Browse files

Unified · Split

2 files
  1. apps/marketing/astro.config.mjs +20 −0
  2. apps/marketing/wrangler.toml +7 −0
apps/marketing/astro.config.mjs+20−0
@@ -1,11 +1,30 @@
11 // @ts-check
2+import { fileURLToPath } from "node:url";
23 import { defineConfig } from "astro/config";
4+import { unstable_readConfig } from "wrangler";
35
46 import tailwindcss from "@tailwindcss/vite";
57 import react from "@astrojs/react";
68
79 import cloudflare from "@astrojs/cloudflare";
810
11+// Single source of truth for public build-time vars: wrangler.toml `[vars]`.
12+// Mirrors apps/cloud, which reads its wrangler.jsonc vars the same way. The
13+// PUBLIC_ ones are inlined into the client bundle via Vite `define`, so the
14+// browser PostHog SDK gets the key at build time; they also remain runtime
15+// Worker bindings.
16+const wranglerPublicDefine = () => {
17+ const config = unstable_readConfig(
18+ { config: fileURLToPath(new URL("./wrangler.toml", import.meta.url)) },
19+ { hideWarnings: true },
20+ );
21+ return Object.fromEntries(
22+ Object.entries(config.vars ?? {})
23+ .filter(([key]) => key.startsWith("PUBLIC_"))
24+ .map(([key, value]) => [`import.meta.env.${key}`, JSON.stringify(value)]),
25+ );
26+};
27+
928 // https://astro.build/config
1029 export default defineConfig({
1130 site: "https://executor.sh",
@@ -13,6 +32,7 @@ export default defineConfig({ · 1 unmodified line
1332 integrations: [react()],
1433 vite: {
1534 plugins: [tailwindcss()],
35+ define: wranglerPublicDefine(),
1636 },
1737
1838 adapter: cloudflare(),
apps/marketing/wrangler.toml+7−0
@@ -1,3 +1,10 @@
11 name = "executor-marketing"
22 compatibility_date = "2026-04-22"
33 compatibility_flags = ["nodejs_compat"]
4+
5+# Public build-time vars, the single source of truth. astro.config.mjs reads the
6+# PUBLIC_ ones from here and inlines them into the client bundle (same approach
7+# apps/cloud uses with its wrangler.jsonc vars). phc_ is a public PostHog project
8+# key, shipped in client JS by design, so it belongs in committed config.
9+[vars]
10+PUBLIC_POSTHOG_KEY = "phc_nNLrNMALpRsfrEkZovUkfMxYbcJvHnsJHeoSPavprgLL"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t