File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed
basic-starter/app/api/revalidate
graphql-starter/app/api/revalidate Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 1- import { revalidatePath } from "next/cache"
1+ import { revalidatePath , revalidateTag } from "next/cache"
22import type { NextRequest } from "next/server"
33
44async function handler ( request : NextRequest ) {
55 const searchParams = request . nextUrl . searchParams
66 const path = searchParams . get ( "path" )
7+ const tags = searchParams . get ( "tags" )
78 const secret = searchParams . get ( "secret" )
89
910 // Validate secret.
1011 if ( secret !== process . env . DRUPAL_REVALIDATE_SECRET ) {
1112 return new Response ( "Invalid secret." , { status : 401 } )
1213 }
1314
14- // Validate path.
15- if ( ! path ) {
16- return new Response ( "Invalid path." , { status : 400 } )
15+ // Either tags or path must be provided .
16+ if ( ! path && ! tags ) {
17+ return new Response ( "Missing path or tags ." , { status : 400 } )
1718 }
1819
1920 try {
20- revalidatePath ( path )
21+ path && revalidatePath ( path )
22+ tags ?. split ( "," ) . forEach ( ( tag ) => revalidateTag ( tag ) )
2123
2224 return new Response ( "Revalidated." )
2325 } catch ( error ) {
Original file line number Diff line number Diff line change 1- import { revalidatePath } from "next/cache"
1+ import { revalidatePath , revalidateTag } from "next/cache"
22import type { NextRequest } from "next/server"
33
44async function handler ( request : NextRequest ) {
55 const searchParams = request . nextUrl . searchParams
66 const path = searchParams . get ( "path" )
7+ const tags = searchParams . get ( "tags" )
78 const secret = searchParams . get ( "secret" )
89
910 // Validate secret.
1011 if ( secret !== process . env . DRUPAL_REVALIDATE_SECRET ) {
1112 return new Response ( "Invalid secret." , { status : 401 } )
1213 }
1314
14- // Validate path.
15- if ( ! path ) {
16- return new Response ( "Invalid path." , { status : 400 } )
15+ // Either tags or path must be provided .
16+ if ( ! path && ! tags ) {
17+ return new Response ( "Missing path or tags ." , { status : 400 } )
1718 }
1819
1920 try {
20- revalidatePath ( path )
21+ path && revalidatePath ( path )
22+ tags ?. split ( "," ) . forEach ( ( tag ) => revalidateTag ( tag ) )
2123
2224 return new Response ( "Revalidated." )
2325 } catch ( error ) {
You can’t perform that action at this time.
0 commit comments