feat(next): supports relative preview URLs (#9755)

Similar to #9746. When deploying to Vercel, preview deployment URLs are
dynamically generated. This breaks `admin.preview` within those
deployments because there is no mechanism by which we can detect and set
that URL within Payload. Although Vercel provides various environment
variables at our disposal, they provide no concrete identifier for
exactly which URL is being currently previewed (you can access the same
deployment from a number of different URLs).

The fix is to support relative `admin.preview` URLs, that way Payload
can prepend the application's top-level domain dynamically at
render-time in order to create a fully qualified URL. So when you visit
a Vercel preview deployment, for example, that deployment's unique URL
is used as the preview redirect, instead of the application's
root/production domain. Note: this does not fix multi-tenancy
single-domain setups, as those still require a static top-level domain
for each tenant.
This commit is contained in:
Jacob Fletcher
2024-12-04 17:01:09 -05:00
committed by GitHub
parent 61a4656ef5
commit 1fc9c47f20
14 changed files with 13 additions and 11 deletions

View File

@@ -11,7 +11,6 @@ const AutosavePosts: CollectionConfig = {
admin: {
useAsTitle: 'title',
defaultColumns: ['title', 'description', 'createdAt', '_status'],
preview: () => 'https://payloadcms.com',
},
versions: {
maxPerDoc: 35,

View File

@@ -6,7 +6,6 @@ const CustomIDs: CollectionConfig = {
slug: customIDSlug,
admin: {
defaultColumns: ['id', 'title', 'createdAt'],
preview: () => 'https://payloadcms.com',
useAsTitle: 'id',
},
fields: [

View File

@@ -44,7 +44,6 @@ const DraftPosts: CollectionConfig = {
},
},
defaultColumns: ['title', 'description', 'createdAt', '_status'],
preview: () => 'https://payloadcms.com',
useAsTitle: 'title',
},
fields: [

View File

@@ -44,7 +44,6 @@ const DraftWithMaxPosts: CollectionConfig = {
},
},
defaultColumns: ['title', 'description', 'createdAt', '_status'],
preview: () => 'https://payloadcms.com',
useAsTitle: 'title',
},
fields: [

View File

@@ -29,7 +29,6 @@ const VersionPosts: CollectionConfig = {
},
admin: {
defaultColumns: ['title', 'description', 'createdAt'],
preview: () => 'https://payloadcms.com',
useAsTitle: 'title',
},
fields: [

View File

@@ -26,9 +26,6 @@ const AutosaveGlobal: GlobalConfig = {
}
},
},
admin: {
preview: () => 'https://payloadcms.com',
},
fields: [
{
name: 'title',

View File

@@ -6,7 +6,6 @@ const DraftWithMaxGlobal: GlobalConfig = {
slug: draftWithMaxGlobalSlug,
label: 'Draft Global',
admin: {
preview: () => 'https://payloadcms.com',
components: {
views: {
edit: {