-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calling revalidation directly as a server action and changing reload …
…action
- Loading branch information
1 parent
af48b78
commit 086665c
Showing
3 changed files
with
18 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 14 additions & 28 deletions
42
frontend/starters/development/lib/trigger-revalidation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
"use server" | ||
|
||
import { revalidatePath } from 'next/cache'; | ||
|
||
export const triggerRevalidation = async (path) => { | ||
const secret = process.env.NEXT_REVALIDATE_SECRET | ||
const baseUrl = process.env.NEXT_HOST // This should ideally be kept secure | ||
const revalidateUrl = `${baseUrl}/api/revalidate?path=${path}&secret=${secret}` | ||
const revalidateUrl = `/${path}`; | ||
const revalidateEditUrl = `/edit/[...puckPath]`; | ||
|
||
try { | ||
const response = await fetch(revalidateUrl, { | ||
method: "GET", | ||
}) | ||
const result = await response | ||
if (result.ok) { | ||
console.log("Page revalidated successfully") | ||
} else { | ||
console.error("Failed to revalidate") | ||
} | ||
} catch (error) { | ||
console.error("Error triggering revalidation:", error) | ||
} | ||
const revalidateEditUrl = `${baseUrl}/api/revalidate?path=/edit/[...puckPath]/page&secret=${secret}` | ||
try { | ||
const response = await fetch(revalidateEditUrl, { | ||
method: "GET", | ||
}) | ||
const result = await response | ||
if (result.ok) { | ||
console.log("Edit page revalidated successfully") | ||
} else { | ||
console.error("Failed to revalidate") | ||
} | ||
await revalidatePath(revalidateUrl, 'page'); // Assuming revalidatePath is an async operation | ||
console.log("Page revalidated"); | ||
|
||
await revalidatePath(revalidateEditUrl, 'page'); | ||
console.log("Edit page revalidated"); | ||
|
||
return "Both pages revalidated successfully"; // Resolving the promise with a success message | ||
} catch (error) { | ||
console.error("Error triggering revalidation:", error) | ||
console.error("Error triggering revalidation:", error); | ||
throw error; // Rejecting the promise with the caught error | ||
} | ||
} | ||
}; |