fix(cache): update debug-mdx route to purge entire cache for Server Actions

This commit is contained in:
2026-06-03 16:27:11 +02:00
parent 3395e6ebf8
commit 1a8ee3f042

View File

@@ -1,28 +1,23 @@
import { NextResponse } from "next/server"; import { NextResponse, NextRequest } from "next/server";
import { revalidatePath } from "next/cache"; import { revalidatePath } from "next/cache";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
export async function GET() { export async function GET(request: NextRequest) {
try { try {
const POSTS_DIR = path.join(process.cwd(), "content/blog"); const searchParams = request.nextUrl.searchParams;
let files = []; const pathParam = searchParams.get("path") || "/";
if (fs.existsSync(POSTS_DIR)) { const typeParam =
files = fs.readdirSync(POSTS_DIR); (searchParams.get("type") as "page" | "layout") || "layout";
}
// Revalidate the two problematic pages // Revalidate the requested path (defaults to entire app via layout)
revalidatePath("/blog/website-as-a-service"); revalidatePath(pathParam, typeParam);
revalidatePath("/blog/zero-overhead-agencies");
revalidatePath("/blog"); // also bust the blog list cache
return NextResponse.json({ return NextResponse.json({
success: true, success: true,
cwd: process.cwd(), revalidatedPath: pathParam,
postsDir: POSTS_DIR, revalidatedType: typeParam,
postsDirExists: fs.existsSync(POSTS_DIR), message: `Cache revalidated for ${pathParam} (${typeParam})`,
files: files,
message: "Cache revalidated for specific paths",
}); });
} catch (err: any) { } catch (err: any) {
return NextResponse.json({ success: false, error: err.message }); return NextResponse.json({ success: false, error: err.message });