fix: add cache revalidation for sitemap.xml file

This commit is contained in:
Dorian Niemiec 2024-09-07 22:12:05 +02:00
parent 4bcc99add8
commit c1ebbac05f
3 changed files with 7 additions and 1 deletions

View file

@ -62,6 +62,7 @@ export const PUT = async (
}; };
revalidatePath(`/changelog/${slug}`); revalidatePath(`/changelog/${slug}`);
revalidatePath("/vulnerabilities"); revalidatePath("/vulnerabilities");
revalidatePath("/sitemap.xml");
return NextResponse.json(serializedResult, { status: 200 }); return NextResponse.json(serializedResult, { status: 200 });
} else { } else {
return NextResponse.json({ message: "Page not found" }, { status: 404 }); return NextResponse.json({ message: "Page not found" }, { status: 404 });
@ -93,6 +94,7 @@ export const DELETE = async (
if (result.deletedCount > 0) { if (result.deletedCount > 0) {
revalidatePath(`/changelog/${slug}`); revalidatePath(`/changelog/${slug}`);
revalidatePath("/vulnerabilities"); revalidatePath("/vulnerabilities");
revalidatePath("/sitemap.xml");
return NextResponse.json( return NextResponse.json(
{ message: "Page deleted successfully" }, { message: "Page deleted successfully" },
{ status: 200 } { status: 200 }

View file

@ -35,6 +35,7 @@ export const POST = async (req: NextRequest) => {
const result = await db.collection("pages").insertOne(newPage); const result = await db.collection("pages").insertOne(newPage);
revalidatePath(`/changelog/${slug}`); revalidatePath(`/changelog/${slug}`);
revalidatePath("/vulnerabilities"); revalidatePath("/vulnerabilities");
revalidatePath("/sitemap.xml");
return NextResponse.json(newPage, { status: 201 }); return NextResponse.json(newPage, { status: 201 });
} catch (error) { } catch (error) {
console.error("Error creating page:", error); console.error("Error creating page:", error);

View file

@ -43,7 +43,10 @@ export async function POST(req: NextRequest) {
try { try {
if (body._type == "blog") { if (body._type == "blog") {
if (body.slug.current) revalidatePath(`/blog/${body.slug.current}`); if (body.slug.current) {
revalidatePath(`/blog/${body.slug.current}`);
revalidatePath("/sitemap.xml");
}
revalidatePath("/blog"); revalidatePath("/blog");
// Change in /blog/page/[id] route and in BlogCards component too! // Change in /blog/page/[id] route and in BlogCards component too!