Skip to content

Commit

Permalink
revalidation on redirects
Browse files Browse the repository at this point in the history
closes #307
  • Loading branch information
ccorda committed Aug 2, 2024
1 parent fa09dc2 commit 9a96314
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions website/src/pages/[[...slug]].js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export async function getStaticProps({
redirect?.destination &&
redirect?.statusCode
) {
return { redirect: redirect };
return {
redirect: redirect,
revalidate: 15,
};
}

if (!preview) {
Expand All @@ -102,7 +105,6 @@ export async function getStaticProps({
return {
notFound: true,
revalidate: 60,
props: {},
};
}
}
Expand All @@ -118,7 +120,6 @@ export async function getStaticProps({
return {
notFound: true,
revalidate: 60,
props: {},
};
}

Expand Down
5 changes: 5 additions & 0 deletions website/src/pages/api/revalidate.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand Down

0 comments on commit 9a96314

Please sign in to comment.