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