Hi I'm deploying a Nextjs 13 app to Vercel and I need to get the Preview generated URL from my code. As the Vercel documentation says:
Whenever a new deployment is created, Vercel will automatically generate a unique URL which you can use to access that particular deployment
So, for example, my deployments URLs look like:
and so on...
Where can I find this URL? Is it available among Vercel System Environment Variables?
Yes. Unique URLs are available as Environment Variables (reference). They can be accessed at runtime and build time with process.env.VERCEL_URL
, and they will be in the format of example-abc123.vercel.app
. Be careful to not use those URLs for production workloads or importing assets, for example, this should never be used:
<script src="https://example-123abc.vercel.app/myscripts.js"></script>
You can read more about others automatically generated URLs it in the Vercel Docs