File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
packages/gitbook-v2/src/app/~gitbook/revalidate Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { type NextRequest , NextResponse } from 'next/server' ;
2
2
3
3
import { withVerifySignature } from '@v2/lib/routes' ;
4
- import { revalidateTag } from 'next/cache' ;
4
+ import { revalidatePath , revalidateTag } from 'next/cache' ;
5
5
6
6
interface JsonBody {
7
7
tags : string [ ] ;
8
+ paths ?: string [ ] ;
8
9
}
9
10
10
11
/**
11
12
* Revalidate cached data based on tags.
12
- * The body should be a JSON with { tags: string[] }
13
+ * The body should be a JSON with { tags: string[], paths?: string[] }
13
14
*/
14
15
export async function POST ( req : NextRequest ) {
15
16
return withVerifySignature < JsonBody > ( req , async ( body ) => {
@@ -22,12 +23,27 @@ export async function POST(req: NextRequest) {
22
23
) ;
23
24
}
24
25
26
+ if ( body . paths && ! Array . isArray ( body . paths ) ) {
27
+ return NextResponse . json (
28
+ {
29
+ error : 'paths must be an array' ,
30
+ } ,
31
+ { status : 400 }
32
+ ) ;
33
+ }
34
+
25
35
body . tags . forEach ( ( tag ) => {
26
36
// biome-ignore lint/suspicious/noConsole: we want to log here
27
37
console . log ( `Revalidating tag: ${ tag } ` ) ;
28
38
revalidateTag ( tag ) ;
29
39
} ) ;
30
40
41
+ body . paths ?. forEach ( ( path ) => {
42
+ // biome-ignore lint/suspicious/noConsole: we want to log here
43
+ console . log ( `Revalidating path: ${ path } ` ) ;
44
+ revalidatePath ( path ) ;
45
+ } ) ;
46
+
31
47
return NextResponse . json ( {
32
48
success : true ,
33
49
} ) ;
You can’t perform that action at this time.
0 commit comments