Skip to content

Commit

Permalink
Invalidate views correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Jan 23, 2024
1 parent efd455d commit a2b1138
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/api/revalidate/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ export const GET = async (request: NextRequest) => {
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) {
return NextResponse.json({message: 'Invalid token'}, {status: 403});
}
const path = request.nextUrl.searchParams.get('slug');

const path = request.nextUrl.searchParams.get('slug')?.replace(/^\//, '');
if (!path) {
return NextResponse.json({message: 'Missing slug'}, {status: 400});
}
const tagsInvalidated = ['paths'];
const tagsInvalidated = ['paths', `paths:${path}`];

if (path.startsWith('views/')) {
tagsInvalidated.push(path.replace('/', ':'))
Expand All @@ -25,5 +26,6 @@ export const GET = async (request: NextRequest) => {

await getAllDrupalPaths(true);
revalidatePath(path);
console.log('invalidated path', path);
return NextResponse.json({revalidated: true, path, tags: tagsInvalidated});
}

0 comments on commit a2b1138

Please sign in to comment.