Skip to content

Commit d74c78a

Browse files
committed
Add revalidatePaths
1 parent 6f8ecd6 commit d74c78a

File tree

1 file changed

+18
-2
lines changed
  • packages/gitbook-v2/src/app/~gitbook/revalidate

1 file changed

+18
-2
lines changed

packages/gitbook-v2/src/app/~gitbook/revalidate/route.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { type NextRequest, NextResponse } from 'next/server';
22

33
import { withVerifySignature } from '@v2/lib/routes';
4-
import { revalidateTag } from 'next/cache';
4+
import { revalidatePath, revalidateTag } from 'next/cache';
55

66
interface JsonBody {
77
tags: string[];
8+
paths?: string[];
89
}
910

1011
/**
1112
* 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[] }
1314
*/
1415
export async function POST(req: NextRequest) {
1516
return withVerifySignature<JsonBody>(req, async (body) => {
@@ -22,12 +23,27 @@ export async function POST(req: NextRequest) {
2223
);
2324
}
2425

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+
2535
body.tags.forEach((tag) => {
2636
// biome-ignore lint/suspicious/noConsole: we want to log here
2737
console.log(`Revalidating tag: ${tag}`);
2838
revalidateTag(tag);
2939
});
3040

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+
3147
return NextResponse.json({
3248
success: true,
3349
});

0 commit comments

Comments
 (0)