From ac55c79ffe840ee59d2935893ebb5682844af5fe Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 10 May 2024 16:12:34 +0200 Subject: [PATCH] =?UTF-8?q?docs:=20explain=20about=20the=20conditional=20d?= =?UTF-8?q?efault=20metadataBase=20on=20vercel=20de=E2=80=A6=20(#65583)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Explain more details about default `metadataBase` (where `metadataBase` is not defined) when it's on Vercel deployment x-ref: https://github.com/vercel/next.js/pull/65089 --------- Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com> --- .../04-functions/generate-metadata.mdx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/02-app/02-api-reference/04-functions/generate-metadata.mdx b/docs/02-app/02-api-reference/04-functions/generate-metadata.mdx index ea36795965ead..2a0e10e3713c6 100644 --- a/docs/02-app/02-api-reference/04-functions/generate-metadata.mdx +++ b/docs/02-app/02-api-reference/04-functions/generate-metadata.mdx @@ -430,8 +430,14 @@ export const metadata = { If not configured, `metadataBase` has a **default value**. -- When [`VERCEL_PROJECT_PRODUCTION_URL`](https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables) or [`VERCEL_URL`](https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables) is detected, it will be used as the **default value**, otherwise it falls back to `http://localhost:${process.env.PORT || 3000}`. This allows Open Graph images to work on both preview and production deployments. -- When overriding the default, we recommend using environment variables to compute the URL. This allows configuring a URL for local development, staging, and production environments. +> On Vercel: +> +> - For production deployments, `VERCEL_PROJECT_PRODUCTION_URL` will be used. +> - For preview deployments, `VERCEL_BRANCH_URL` will take priority, and fallback to `VERCEL_URL` if it's not present. +> +> If these values are present they will be used as the **default value** of `metadataBase`, otherwise it falls back to `http://localhost:${process.env.PORT || 3000}`. This allows Open Graph images to work on both local build and Vercel preview and production deployments. When overriding the default, we recommend using environment variables to compute the URL. This allows configuring a URL for local development, staging, and production environments. +> +> See more details about these environment variables in the [System Environment Variables](https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables) docs. #### URL Composition