export const getURL = () => {
let url =
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
'http://localhost:3000/';
// Make sure to include `https://` when not localhost.
url = url.startsWith('http') ? url : `https://${url}`;
// Make sure to include a trailing `/`.
url = url.endsWith('/') ? url : `${url}/`;
return url;
};
and I set NEXT_PUBLIC_SITE_URL to my production domain.
The domain troubleshooting guide can help with most custom domain configuration issues. You might be able to use that guide to solve it before a human is available to help you. Then you can come back here and share the answer for bonus points.
You can also use v0 to narrow down the possibilities.
This is happening because the following expression will always evaluate to the NEXT_PUBLIC_SITE_URL environment variable if it’s available.
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
'http://localhost:3000/';
If you are using a specific branch for testing then I’d recommend using the VERCEL_BRANCH_URL instead of the VERCEL_URL, which will solve the wildcard url for the Google Console as well.
For the NEXT_PUBLIC_SITE_URL environment variable, you should restrict it only to the production environment.