// Generate public/config.json โ€” the runtime config the account / orders / // scan / purchase / remote-desktop pages read via /landing/bigapi.js. This // replaces the old /api/config server route so the site can ship as a static // bundle (no Node server). Every value here is PUBLIC (the old React // site baked the same ones into its client bundle) โ€” never put secrets here. // // Values come from the build environment; unset -> the local mock (/api/mock, // served by `next dev`). Run at build time and by `npm run local`. import fs from "node:fs"; const mock = "/api/mock"; const config = { apiServerUrl: process.env.BIG_API_SERVER_URL || mock, cloudApiServerUrl: process.env.BIG_CLOUD_API_URL || mock, apiKey: process.env.BIG_API_KEY || "mock-api-key", rdcServerHost: process.env.BIG_RDC_SERVER_HOST || `${mock}/rdc`, stripePublishableKey: process.env.BIG_STRIPE_PK || "pk_test_1nrqtk8swOmQqgChY2eLofrc", mock: !process.env.BIG_API_SERVER_URL, }; fs.mkdirSync("public", { recursive: true }); fs.writeFileSync("public/config.json", JSON.stringify(config, null, 2) + "\n"); console.log( `config.json written (${config.mock ? "MOCK" : "live API"}: ${config.apiServerUrl})`, ); // Staging builds also ship config.prod.json (the production API tier) so a // tester can flip a staging page onto prod APIs with ?api=prod โ€” no rebuild, // no republish (see src/site/partials/bigapi.js and STAGE-TEST-RELEASE.md ยง3). // Production builds set no BIG_PROD_* vars, ship no config.prod.json, and the // switch stays inert there. These values are public, same as config.json. if (process.env.BIG_PROD_API_SERVER_URL) { const prod = { apiServerUrl: process.env.BIG_PROD_API_SERVER_URL, cloudApiServerUrl: process.env.BIG_PROD_CLOUD_API_URL || mock, apiKey: process.env.BIG_PROD_API_KEY || "mock-api-key", rdcServerHost: process.env.BIG_PROD_RDC_SERVER_HOST || `${mock}/rdc`, stripePublishableKey: process.env.BIG_PROD_STRIPE_PK || config.stripePublishableKey, mock: false, }; fs.writeFileSync( "public/config.prod.json", JSON.stringify(prod, null, 2) + "\n", ); console.log(`config.prod.json written (prod tier: ${prod.apiServerUrl})`); } else if (fs.existsSync("public/config.prod.json")) { fs.rmSync("public/config.prod.json"); console.log("stale config.prod.json removed (no BIG_PROD_* env)"); }