mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
* show cms blog posts in www * remove contentlayer from www * outputFileTracingExcludes * update remotePatterns * fetch cms posts server-side with revalidation * add cms env vars to turbo.json * add www env vars to turbo.json * include cms posts in www sitemap * add migration to remove image from cms post * update cms meta image mapping in www
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { draftMode } from 'next/headers'
|
|
import { redirect } from 'next/navigation'
|
|
|
|
export async function GET(request: Request) {
|
|
const draft = await draftMode()
|
|
const { searchParams } = new URL(request.url)
|
|
const secret = searchParams.get('secret')
|
|
const slug = searchParams.get('slug')
|
|
const path = searchParams.get('path') || 'blog'
|
|
|
|
// Get the expected secret with fallback to match CMS configuration
|
|
const expectedSecret = process.env.CMS_PREVIEW_SECRET
|
|
|
|
if (secret !== expectedSecret) {
|
|
console.error('[preview] Token mismatch:', {
|
|
received: secret,
|
|
expected: expectedSecret,
|
|
})
|
|
return new Response(
|
|
`Invalid token. Expected: ${expectedSecret?.slice(0, 3)}..., Received: ${secret?.slice(0, 3)}...`,
|
|
{ status: 401 }
|
|
)
|
|
}
|
|
|
|
if (!slug) {
|
|
console.error('[preview] No slug provided')
|
|
return new Response('No slug in the request', { status: 401 })
|
|
}
|
|
|
|
// Enable Draft Mode by setting the cookie
|
|
draft.enable()
|
|
|
|
// Redirect to the path from the fetched post
|
|
redirect(`/${path}/${slug}`)
|
|
}
|