My blog looked fine. Its metadata did not.
Every page loaded and every post rendered. But the canonical link, the social preview tags and the sitemap all said my blog lived at http://localhost:3000.
The cause was a fix I had made earlier. A build once failed because one URL was empty, and I solved it with a safe default. After I moved the blog to Vercel, that default quietly filled the gap.
The first problem was loud. It stopped the build. The second one was quiet. Every build passed, and every page shipped with the wrong address.
The Build That Failed
My blog builds all of its public links from one value: the site's own address. The RSS feed uses it too.
Without that value, the build failed with an invalid URL error. It was annoying, but it was clear. The build stopped and said what was wrong.
The Fix That Made Sense
I gave the value a default, so a missing address would never break a build again:
export const SITE_URL = ( process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000" ).replace(/\/$/, ""); It was a reasonable choice. Local builds and test builds just worked.
But I had swapped a loud failure for a quiet guess.
The Move That Left One Setting Behind
When I moved hosting to Vercel, I copied the secrets over carefully: the database, sign in and storage. The site's address is not a secret, so it was not on that list.
Next.js writes NEXT_PUBLIC_ values into the site when it is built. With no address set, the build used my default and wrote localhost:3000 into every page's metadata. No error and no warning.
Nobody Could See It
The wrong address only lived in the parts of a page people never read but search engines always do:
| What the page says about itself | Before | After |
|---|---|---|
| Canonical link | http://localhost:3000/posts/... | https://blog.lalitbagga.com/posts/... |
Social preview link (og:url) | http://localhost:3000/posts/... | https://blog.lalitbagga.com/posts/... |
| Sitemap entries | every one on localhost | none on localhost |
How I Found It
I was planning my next article and pulled the list of posts from my sitemap. Every link started with http://localhost:3000.
I opened a live post and checked its canonical link, the address search engines treat as the real one. Same thing.
The Fix, and the Check
The fix was one setting in Vercel and a fresh build. Saving the setting alone would not have been enough, because the value is written in at build time.
Then I checked what the site now said about itself:
curl -s https://blog.lalitbagga.com/sitemap.xml | grep -c localhost The answer was 0. Every post's canonical link now shows the real domain.
What Comes Next
The default stays for local work, where it helps. Production builds will stop instead of guessing:
const url = process.env.NEXT_PUBLIC_SITE_URL; if (!url && process.env.VERCEL_ENV === "production") { throw new Error("NEXT_PUBLIC_SITE_URL is missing in a production build"); } The lesson I am keeping is simple. A default protects the build, not what the build produces. For anything the outside world reads, like canonical links, login callbacks and webhook addresses, I would rather have a failed build than a passing one that is wrong.

