Validate required settings at boot and fail the deploy
List every variable the app needs, reject missing and whitespace-only values, and run this from your build command so a bad deploy fails before it goes live. Check the values the live code reads, not only that the name exists.
const required = ["DATABASE_URL", "STRIPE_SECRET_KEY", "STRIPE_WEBHOOK_SECRET", "TURNSTILE_SECRET"];
const bad = required.filter((k) => !process.env[k]?.trim());
if (bad.length) throw new Error(`Missing or empty: ${bad.join(", ")}`);
Set each variable for the right environment, then redeploy
In the host's dashboard, tick Production for every variable production needs. Because changes reach only new deployments, trigger a fresh build after every edit. Set framework variables that the browser reads before the build runs, since they are frozen into the bundle.
Keep server secrets out of the browser bundle, and scan the output
Use a client-exposed prefix such as NEXT_PUBLIC_ only for values that are meant to be public, and read secrets in server code, route handlers or functions. Then search the built files for key shapes and fail the pipeline on a match.
if grep -rEl 'sk_(live|test)_|whsec_' .next/static dist build 2>/dev/null; then
echo "secret found in client bundle"; exit 1
fi
Keep one list of every origin and use it everywhere
Derive the CORS allowlist, redirect URIs and trusted hosts from one list. When requests carry credentials, reply with the specific origin, not a wildcard, and add Vary: Origin when the value changes per request. Answer the OPTIONS preflight with the allowed methods and headers.
const allowed = new Set(["https://www.example.com", "https://app.example.com"]);
function applyCors(req: Request, headers: Headers) {
const origin = req.headers.get("origin");
if (origin && allowed.has(origin)) {
headers.set("Access-Control-Allow-Origin", origin);
headers.append("Vary", "Origin");
}
}
Test every hostname the way a visitor or monitor reaches it
Compare the default host with the custom domain, and read the certificate the custom domain serves. If the custom domain loops, check whether the origin redirects to HTTPS while the CDN talks to it over HTTP. Cloudflare's Flexible mode with an HTTPS redirect at the origin causes this loop, and Full or Full (strict) fixes it. For monitors blocked by deployment protection, use the host's bypass for automation instead of switching protection off. If the domain should receive mail, also confirm it has an MX record.
curl -sI https://my-app.vercel.app | head -5
curl -sI https://www.example.com | head -5
openssl s_client -connect www.example.com:443 -servername www.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -dates
dig +short MX example.com
Fix validation before you retry certificate issuance
Let's Encrypt allows 5 authorization failures per identifier per account per hour, 5 certificates per exact set of names per 7 days, and 50 per registered domain per 7 days. Repeated retries against a broken challenge record use up those limits. Correct the DNS record or validation method first, then retry once.
Rehearse a rotation before you need one
For each secret, add the new value, deploy, confirm traffic works, then revoke the old one. Stripe lets you roll an endpoint secret and keep the old one valid for up to 7 days, so both are accepted while you update the server. Run the same drill for your email provider key, since a disabled key stops all sends at once.