-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
2 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1 @@ | ||
import { draftMode } from "next/headers"; | ||
import { redirect } from "next/navigation"; | ||
import { getPreviewPostBySlug } from "../../../lib/api"; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const secret = searchParams.get("secret"); | ||
const slug = searchParams.get("slug"); | ||
|
||
if (secret !== process.env.CONTENTFUL_PREVIEW_SECRET) { | ||
return new Response("Invalid token", { status: 401 }); | ||
} | ||
|
||
const post = await getPreviewPostBySlug(slug); | ||
|
||
if (!post) { | ||
return new Response("Invalid slug", { status: 401 }); | ||
} | ||
|
||
draftMode().enable(); | ||
redirect(`/posts/${post.slug}`); | ||
} | ||
export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters