Reputation: 481
I'm working on a Next.js project where I need to dynamically generate Open Graph images. My implementation works locally, but I'm facing issues when deploying to production on Vercel and Netlify.
Local Environment:
Vercel Deployment:
Netlify Deployment:
localhost
instead of the production URL.Questions:
localhost
on Netlify, and how can I correct it to use the production URL?Any insights or suggestions to resolve these issues would be greatly appreciated!
Reference: I followed the Vercel Documentation for this implementation.
Upvotes: 4
Views: 1120
Reputation: 1534
Regarding:
You should be able to use metadataBaseUrl
in your metadata
object. You could use it this way, in example for Vercel deployments:
metadataBase: process.env.VERCEL_URL
? new URL(`https://${process.env.VERCEL_URL}`)
: new URL(`http://localhost:${process.env.PORT || 3000}`),
Same would apply for a different env variable or deployment service.
Now, regarding:
It exactly happens the same to me. I found this issue in github too: https://github.com/vercel/next.js/discussions/50546#discussioncomment-8052317
EDIT: I fixed it using a hardcoded metadataBase
instead of the autogenerated VERCEL_URL
, which uses the deploy link instead of my own domain (which anyways should be public, but idk)
EDIT2: Ok, this was the issue, I had it enabled by default for the new project this config:
which asks for auth for every domain except production ones and it seems somehow Vercel doesnt take autogenerated URL as a production link even though it is.
Upvotes: 3