Files
supabase/apps/www/app/api-v2/cms/revalidate/route.ts
Francesco Sansalvadore b4922199cd unblock cms draft mode (#38409)
* remove port from cms start script

* address cors

* 30s revalidation on blog index

* fix types

* remove duplicate cache strategy

* disable graphql

* fix cms build

* fix ProductDropdown crash

* fix env var turbo
2025-09-16 13:03:13 +02:00

33 lines
956 B
TypeScript

import { revalidatePath } from 'next/cache'
import { NextRequest, NextResponse } from 'next/server'
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const { secret, path } = body
// Check for secret to confirm this is a valid request
if (secret !== process.env.CMS_PREVIEW_SECRET) {
return NextResponse.json({ message: 'Invalid token' }, { status: 401 })
}
if (!path) {
return NextResponse.json({ message: 'Missing path parameter' }, { status: 400 })
}
// This will revalidate the specific page
revalidatePath(path)
return NextResponse.json({ revalidated: true, path })
} catch (error) {
console.error('[Revalidate API] Error during revalidation:', error)
return NextResponse.json(
{
message: 'Error revalidating',
error: error instanceof Error ? error.message : 'Unknown error',
},
{ status: 500 }
)
}
}