Skip to content

Commit 8723db8

Browse files
authored
feat(app): #17 add redeploy hook (#29)
* feat(app): 17 add redeploy hook and use it when Events are changed * fix(app): 16 remove localhost previews * chore(server): 17 Don't redeploy from dev environments
1 parent 02237b6 commit 8723db8

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/collections/Events.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import {
44
lexicalEditor,
55
lexicalHTML,
66
} from "@payloadcms/richtext-lexical";
7+
import { redeploy } from "../hooks";
78

89
export const Events: CollectionConfig = {
910
slug: "events",
11+
hooks: {
12+
afterChange: [redeploy],
13+
},
1014
admin: {
1115
useAsTitle: "title",
12-
preview: (doc) => doc?.slug != null ? `http://localhost:5173/events/${doc.slug}` : null,
1316
},
1417
access: {
1518
read: () => true,
@@ -29,7 +32,7 @@ export const Events: CollectionConfig = {
2932
admin: {
3033
date: {
3134
displayFormat: "dd.MM.yyyy",
32-
}
35+
},
3336
},
3437
required: true,
3538
},
@@ -39,7 +42,7 @@ export const Events: CollectionConfig = {
3942
admin: {
4043
date: {
4144
displayFormat: "dd.MM.yyyy",
42-
}
45+
},
4346
},
4447
required: true,
4548
},

src/hooks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const redeploy = async () => {
2+
// uses Cloudflare Deploy Hooks
3+
// see https://developers.cloudflare.com/pages/configuration/deploy-hooks/
4+
// In local development we don't want any redeployments though
5+
if (process.env.CLOUDFLARE_DEPLOY_HOOK) {
6+
await fetch(process.env.CLOUDFLARE_DEPLOY_HOOK, { method: "POST" });
7+
}
8+
};

0 commit comments

Comments
 (0)