File tree Expand file tree Collapse file tree 2 files changed +2
-22
lines changed
Expand file tree Collapse file tree 2 files changed +2
-22
lines changed Original file line number Diff line number Diff line change 1- import { draftMode } from "next/headers" ;
2- import { redirect } from "next/navigation" ;
3- import { getPreviewPostBySlug } from "../../../lib/api" ;
4-
5- export async function GET ( request : Request ) {
6- const { searchParams } = new URL ( request . url ) ;
7- const secret = searchParams . get ( "secret" ) ;
8- const slug = searchParams . get ( "slug" ) ;
9-
10- if ( secret !== process . env . CONTENTFUL_PREVIEW_SECRET ) {
11- return new Response ( "Invalid token" , { status : 401 } ) ;
12- }
13-
14- const post = await getPreviewPostBySlug ( slug ) ;
15-
16- if ( ! post ) {
17- return new Response ( "Invalid slug" , { status : 401 } ) ;
18- }
19-
20- draftMode ( ) . enable ( ) ;
21- redirect ( `/posts/${ post . slug } ` ) ;
22- }
1+ export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router" ;
Original file line number Diff line number Diff line change 99 "dependencies" : {
1010 "@contentful/rich-text-react-renderer" : " ^15.17.1" ,
1111 "@contentful/rich-text-types" : " ^16.2.1" ,
12+ "@contentful/vercel-nextjs-toolkit" : " latest" ,
1213 "@tailwindcss/typography" : " 0.5.9" ,
1314 "@types/node" : " ^20.5.0" ,
1415 "@types/react" : " ^18.2.20" ,
You can’t perform that action at this time.
0 commit comments