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.
Unified · Split
| @@ -1,11 +1,30 @@ | ||
| 1 | 1 | // @ts-check |
| 2 | +import { fileURLToPath } from "node:url"; | |
| 2 | 3 | import { defineConfig } from "astro/config"; |
| 4 | +import { unstable_readConfig } from "wrangler"; | |
| 3 | 5 | |
| 4 | 6 | import tailwindcss from "@tailwindcss/vite"; |
| 5 | 7 | import react from "@astrojs/react"; |
| 6 | 8 | |
| 7 | 9 | import cloudflare from "@astrojs/cloudflare"; |
| 8 | 10 | |
| 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 | + | |
| 9 | 28 | // https://astro.build/config |
| 10 | 29 | export default defineConfig({ |
| 11 | 30 | site: "https://executor.sh", |
| @@ -13,6 +32,7 @@ export default defineConfig({ · 1 unmodified line | ||
| 13 | 32 | integrations: [react()], |
| 14 | 33 | vite: { |
| 15 | 34 | plugins: [tailwindcss()], |
| 35 | + define: wranglerPublicDefine(), | |
| 16 | 36 | }, |
| 17 | 37 | |
| 18 | 38 | adapter: cloudflare(), |
| @@ -1,3 +1,10 @@ | ||
| 1 | 1 | name = "executor-marketing" |
| 2 | 2 | compatibility_date = "2026-04-22" |
| 3 | 3 | 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" | |