Skip to content

Commit 0f53b5b

Browse files
committed
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.
1 parent b74c365 commit 0f53b5b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

apps/marketing/astro.config.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
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",
1231
output: "server",
1332
integrations: [react()],
1433
vite: {
1534
plugins: [tailwindcss()],
35+
define: wranglerPublicDefine(),
1636
},
1737

1838
adapter: cloudflare(),

apps/marketing/wrangler.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

0 commit comments

Comments
 (0)