Skip to content

Commit b0c9b41

Browse files
authored
templates: website template added changes for seed script, relative live preview URLs and fixed endpoint status code (#9808)
1 parent 60ceeb0 commit b0c9b41

File tree

10 files changed

+1760
-4922
lines changed

10 files changed

+1760
-4922
lines changed

templates/website/pnpm-lock.yaml

Lines changed: 1696 additions & 4842 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/website/src/app/(frontend)/next/seed/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ export async function POST(
3333

3434
return Response.json({ success: true })
3535
} catch {
36-
return new Response('Error seeding data.')
36+
return new Response('Error seeding data.', { status: 500 })
3737
}
3838
}

templates/website/src/collections/Pages/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
OverviewField,
2121
PreviewField,
2222
} from '@payloadcms/plugin-seo/fields'
23-
import { getServerSideURL } from '@/utilities/getURL'
2423

2524
export const Pages: CollectionConfig<'pages'> = {
2625
slug: 'pages',
@@ -46,7 +45,7 @@ export const Pages: CollectionConfig<'pages'> = {
4645
collection: 'pages',
4746
})
4847

49-
return `${getServerSideURL()}${path}`
48+
return path
5049
},
5150
},
5251
preview: (data) => {
@@ -55,7 +54,7 @@ export const Pages: CollectionConfig<'pages'> = {
5554
collection: 'pages',
5655
})
5756

58-
return `${getServerSideURL()}${path}`
57+
return path
5958
},
6059
useAsTitle: 'title',
6160
},

templates/website/src/collections/Posts/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
PreviewField,
2727
} from '@payloadcms/plugin-seo/fields'
2828
import { slugField } from '@/fields/slug'
29-
import { getServerSideURL } from '@/utilities/getURL'
3029

3130
export const Posts: CollectionConfig<'posts'> = {
3231
slug: 'posts',
@@ -57,7 +56,7 @@ export const Posts: CollectionConfig<'posts'> = {
5756
collection: 'posts',
5857
})
5958

60-
return `${getServerSideURL()}${path}`
59+
return path
6160
},
6261
},
6362
preview: (data) => {
@@ -66,7 +65,7 @@ export const Posts: CollectionConfig<'posts'> = {
6665
collection: 'posts',
6766
})
6867

69-
return `${getServerSideURL()}${path}`
68+
return path
7069
},
7170
useAsTitle: 'title',
7271
},

templates/website/src/endpoints/seed/index.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ export const seed = async ({
5959
collections.map((collection) => payload.db.deleteMany({ collection, req, where: {} })),
6060
)
6161

62+
await Promise.all(
63+
collections
64+
.filter((collection) => Boolean(payload.collections[collection].config.versions))
65+
.map((collection) => payload.db.deleteVersions({ collection, req, where: {} })),
66+
)
67+
6268
payload.logger.info(`— Seeding demo author and user...`)
6369

6470
await payload.delete({
@@ -234,29 +240,27 @@ export const seed = async ({
234240
})
235241

236242
// update each post with related posts
237-
await Promise.all([
238-
payload.update({
239-
id: post1Doc.id,
240-
collection: 'posts',
241-
data: {
242-
relatedPosts: [post2Doc.id, post3Doc.id],
243-
},
244-
}),
245-
payload.update({
246-
id: post2Doc.id,
247-
collection: 'posts',
248-
data: {
249-
relatedPosts: [post1Doc.id, post3Doc.id],
250-
},
251-
}),
252-
payload.update({
253-
id: post3Doc.id,
254-
collection: 'posts',
255-
data: {
256-
relatedPosts: [post1Doc.id, post2Doc.id],
257-
},
258-
}),
259-
])
243+
await payload.update({
244+
id: post1Doc.id,
245+
collection: 'posts',
246+
data: {
247+
relatedPosts: [post2Doc.id, post3Doc.id],
248+
},
249+
})
250+
await payload.update({
251+
id: post2Doc.id,
252+
collection: 'posts',
253+
data: {
254+
relatedPosts: [post1Doc.id, post3Doc.id],
255+
},
256+
})
257+
await payload.update({
258+
id: post3Doc.id,
259+
collection: 'posts',
260+
data: {
261+
relatedPosts: [post1Doc.id, post2Doc.id],
262+
},
263+
})
260264

261265
payload.logger.info(`— Seeding contact form...`)
262266

templates/with-vercel-website/src/app/(frontend)/next/seed/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ export async function POST(
3333

3434
return Response.json({ success: true })
3535
} catch {
36-
return new Response('Error seeding data.')
36+
return new Response('Error seeding data.', { status: 500 })
3737
}
3838
}

templates/with-vercel-website/src/collections/Pages/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
OverviewField,
2121
PreviewField,
2222
} from '@payloadcms/plugin-seo/fields'
23-
import { getServerSideURL } from '@/utilities/getURL'
2423

2524
export const Pages: CollectionConfig<'pages'> = {
2625
slug: 'pages',
@@ -46,7 +45,7 @@ export const Pages: CollectionConfig<'pages'> = {
4645
collection: 'pages',
4746
})
4847

49-
return `${getServerSideURL()}${path}`
48+
return path
5049
},
5150
},
5251
preview: (data) => {
@@ -55,7 +54,7 @@ export const Pages: CollectionConfig<'pages'> = {
5554
collection: 'pages',
5655
})
5756

58-
return `${getServerSideURL()}${path}`
57+
return path
5958
},
6059
useAsTitle: 'title',
6160
},

templates/with-vercel-website/src/collections/Posts/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
PreviewField,
2727
} from '@payloadcms/plugin-seo/fields'
2828
import { slugField } from '@/fields/slug'
29-
import { getServerSideURL } from '@/utilities/getURL'
3029

3130
export const Posts: CollectionConfig<'posts'> = {
3231
slug: 'posts',
@@ -57,7 +56,7 @@ export const Posts: CollectionConfig<'posts'> = {
5756
collection: 'posts',
5857
})
5958

60-
return `${getServerSideURL()}${path}`
59+
return path
6160
},
6261
},
6362
preview: (data) => {
@@ -66,7 +65,7 @@ export const Posts: CollectionConfig<'posts'> = {
6665
collection: 'posts',
6766
})
6867

69-
return `${getServerSideURL()}${path}`
68+
return path
7069
},
7170
useAsTitle: 'title',
7271
},

templates/with-vercel-website/src/endpoints/seed/index.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ export const seed = async ({
5959
collections.map((collection) => payload.db.deleteMany({ collection, req, where: {} })),
6060
)
6161

62+
await Promise.all(
63+
collections
64+
.filter((collection) => Boolean(payload.collections[collection].config.versions))
65+
.map((collection) => payload.db.deleteVersions({ collection, req, where: {} })),
66+
)
67+
6268
payload.logger.info(`— Seeding demo author and user...`)
6369

6470
await payload.delete({
@@ -234,29 +240,27 @@ export const seed = async ({
234240
})
235241

236242
// update each post with related posts
237-
await Promise.all([
238-
payload.update({
239-
id: post1Doc.id,
240-
collection: 'posts',
241-
data: {
242-
relatedPosts: [post2Doc.id, post3Doc.id],
243-
},
244-
}),
245-
payload.update({
246-
id: post2Doc.id,
247-
collection: 'posts',
248-
data: {
249-
relatedPosts: [post1Doc.id, post3Doc.id],
250-
},
251-
}),
252-
payload.update({
253-
id: post3Doc.id,
254-
collection: 'posts',
255-
data: {
256-
relatedPosts: [post1Doc.id, post2Doc.id],
257-
},
258-
}),
259-
])
243+
await payload.update({
244+
id: post1Doc.id,
245+
collection: 'posts',
246+
data: {
247+
relatedPosts: [post2Doc.id, post3Doc.id],
248+
},
249+
})
250+
await payload.update({
251+
id: post2Doc.id,
252+
collection: 'posts',
253+
data: {
254+
relatedPosts: [post1Doc.id, post3Doc.id],
255+
},
256+
})
257+
await payload.update({
258+
id: post3Doc.id,
259+
collection: 'posts',
260+
data: {
261+
relatedPosts: [post1Doc.id, post2Doc.id],
262+
},
263+
})
260264

261265
payload.logger.info(`— Seeding contact form...`)
262266

templates/with-vercel-website/src/endpoints/seedHandler.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)