The donate redirect checks three hosting providers before it picks a URL
The donation API creates a Stripe Checkout Session with a success_url that points to the thanks page. That URL needs to be absolute — Stripe redirects the browser after payment, so a relative path would break. The getBaseUrl function resolves the correct domain by checking three environment variables in order. First it reads NEXT_PUBLIC_BASE_URL — the explicit override that any deployment can set. If that is missing it reads VERCEL_URL, which Vercel injects automatically on every deployment but without the https prefix, so the function prepends it. If that is also missing it reads RAILWAY_PUBLIC_DOMAIN, which Railway injects the same way — a bare hostname that needs the protocol added. If all three are absent the function returns the production domain hardcoded as a final fallback. Four lines, three providers, one URL. The same donate route works on localhost with NEXT_PUBLIC_BASE_URL set to http://localhost:3000, on a Vercel preview branch with VERCEL_URL set automatically to something like jamesmusic-uk-git-feature-jamesmusicltd.vercel.app, on Railway staging, and on the live production site. No conditional logic in the route handler. No environment detection. The getBaseUrl function picks the right domain and the route builds the redirect from there. The cancel_url uses the same function so both the success and cancellation redirects resolve consistently. One four-line utility and every deployment environment gets correct Stripe redirects without any configuration beyond what the hosting provider already supplies.
Comments coming soon
Sign in with TikTok to leave a comment. Coming soon.