From 9a9631403fbffab36d7e1d559f1b141c8cefb4b5 Mon Sep 17 00:00:00 2001 From: Cameron Corda Date: Fri, 2 Aug 2024 07:16:57 -0700 Subject: [PATCH] revalidation on redirects closes #307 --- website/src/pages/[[...slug]].js | 7 ++++--- website/src/pages/api/revalidate.js | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/website/src/pages/[[...slug]].js b/website/src/pages/[[...slug]].js index 16e1c0d..d5bb837 100644 --- a/website/src/pages/[[...slug]].js +++ b/website/src/pages/[[...slug]].js @@ -89,7 +89,10 @@ export async function getStaticProps({ redirect?.destination && redirect?.statusCode ) { - return { redirect: redirect }; + return { + redirect: redirect, + revalidate: 15, + }; } if (!preview) { @@ -102,7 +105,6 @@ export async function getStaticProps({ return { notFound: true, revalidate: 60, - props: {}, }; } } @@ -118,7 +120,6 @@ export async function getStaticProps({ return { notFound: true, revalidate: 60, - props: {}, }; } diff --git a/website/src/pages/api/revalidate.js b/website/src/pages/api/revalidate.js index f8929f0..27af3d4 100644 --- a/website/src/pages/api/revalidate.js +++ b/website/src/pages/api/revalidate.js @@ -1,3 +1,6 @@ +// this route is called by the stellate wp plugin to revalidate pages after WP is updated +// https://nextjs.org/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation + export default async function handler(req, res) { const { secret, paths } = req.body; @@ -7,11 +10,13 @@ export default async function handler(req, res) { } if (!paths || paths.length === 0) { + console.log('No paths provided for revalidation'); return void res.json({ revalidated: false }); } try { await Promise.all(paths.map((path) => res.revalidate(path))); + console.log('Paths successfully revalidated:', paths); return void res.json({ revalidated: true }); } catch (err) { // If there was an error, Next.js will continue