diff --git a/frontend/editor/vite.config.ts b/frontend/editor/vite.config.ts index 3f51f7ba3..b6594c680 100644 --- a/frontend/editor/vite.config.ts +++ b/frontend/editor/vite.config.ts @@ -13,6 +13,34 @@ const gzipPromise = promisify(gzip); const brotliPromise = promisify(brotliCompress); const __dirname = path.dirname(fileURLToPath(import.meta.url)); +// TEMP DEBUG — writes a build-info.txt into dist/ on every build so we can +// curl https:////build-info.txt to confirm a fresh deploy landed +// and which env vars the build host actually received. Values are masked to +// (set)/(unset) so nothing real is exposed via the publicly-served file; the +// build log (vite-config-debug below) shows actual values for the project +// owner. Timestamp guarantees the file differs every build, forcing upload. +function buildInfoPlugin(): PluginOption { + const mask = (v: string | undefined) => (v ? "(set)" : "(unset)"); + return { + name: "debug-build-info", + apply: "build" as const, + async closeBundle() { + const distDir = path.resolve(__dirname, "dist"); + const contents = [ + `BuildTime=${new Date().toISOString()}`, + `VITE_API_BASE_URL=${mask(process.env.VITE_API_BASE_URL)}`, + `RUN_SUBPATH=${mask(process.env.RUN_SUBPATH)}`, + `VITE_SUPABASE_URL=${mask(process.env.VITE_SUPABASE_URL)}`, + `VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY=${mask(process.env.VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY)}`, + `STIRLING_FLAVOR=${mask(process.env.STIRLING_FLAVOR)}`, + "", + ].join("\n"); + await fs.mkdir(distDir, { recursive: true }); + await fs.writeFile(path.join(distDir, "build-info.txt"), contents); + }, + }; +} + function compressStaticCopyPlugin(): PluginOption { return { name: "compress-static-copy", @@ -97,6 +125,28 @@ export default defineConfig(async ({ mode }) => { // frontend/editor/ the cwd-based lookup would miss editor/.env*. const env = loadEnv(mode, import.meta.dirname, ""); + // TEMP DEBUG — surface build-time env values so we can confirm what the + // build host (Cloudflare / CI) is actually passing through. Safe to remove + // once we've stopped chasing env-var routing bugs. + // eslint-disable-next-line no-console + console.log( + "[vite-config-debug]", + JSON.stringify( + { + mode, + VITE_API_BASE_URL_processEnv: process.env.VITE_API_BASE_URL ?? "(unset)", + VITE_API_BASE_URL_loadEnv: env.VITE_API_BASE_URL ?? "(unset)", + RUN_SUBPATH: process.env.RUN_SUBPATH ?? env.RUN_SUBPATH ?? "(unset)", + VITE_SUPABASE_URL: env.VITE_SUPABASE_URL ? "(set)" : "(unset)", + VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY: env.VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY + ? "(set)" + : "(unset)", + }, + null, + 2, + ), + ); + // Effective mode: --mode > STIRLING_FLAVOR > ENABLE_SAAS > DISABLE_ADDITIONAL_FEATURES > proprietary. const explicitMode = (VALID_MODES as readonly string[]).includes(mode) ? (mode as BuildMode) @@ -202,6 +252,7 @@ export default defineConfig(async ({ mode }) => { ], }), compressStaticCopyPlugin(), + buildInfoPlugin(), ], server: { host: true,