From 9951a357acf39d9a87cbf17c84a0fe5930759b86 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 3 Jun 2026 16:27:11 +0200 Subject: [PATCH] fix(cache): update debug-mdx route to purge entire cache for Server Actions --- apps/web/app/debug-mdx/route.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/apps/web/app/debug-mdx/route.ts b/apps/web/app/debug-mdx/route.ts index 7ed34f7..5c9f79e 100644 --- a/apps/web/app/debug-mdx/route.ts +++ b/apps/web/app/debug-mdx/route.ts @@ -1,28 +1,23 @@ -import { NextResponse } from "next/server"; +import { NextResponse, NextRequest } from "next/server"; import { revalidatePath } from "next/cache"; import fs from "fs"; import path from "path"; -export async function GET() { +export async function GET(request: NextRequest) { try { - const POSTS_DIR = path.join(process.cwd(), "content/blog"); - let files = []; - if (fs.existsSync(POSTS_DIR)) { - files = fs.readdirSync(POSTS_DIR); - } + const searchParams = request.nextUrl.searchParams; + const pathParam = searchParams.get("path") || "/"; + const typeParam = + (searchParams.get("type") as "page" | "layout") || "layout"; - // Revalidate the two problematic pages - revalidatePath("/blog/website-as-a-service"); - revalidatePath("/blog/zero-overhead-agencies"); - revalidatePath("/blog"); // also bust the blog list cache + // Revalidate the requested path (defaults to entire app via layout) + revalidatePath(pathParam, typeParam); return NextResponse.json({ success: true, - cwd: process.cwd(), - postsDir: POSTS_DIR, - postsDirExists: fs.existsSync(POSTS_DIR), - files: files, - message: "Cache revalidated for specific paths", + revalidatedPath: pathParam, + revalidatedType: typeParam, + message: `Cache revalidated for ${pathParam} (${typeParam})`, }); } catch (err: any) { return NextResponse.json({ success: false, error: err.message });