Skip to content

Commit 7d3bdf3

Browse files
committed
feat: add contentful sdk
1 parent 31eedcd commit 7d3bdf3

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1 @@
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";

examples/cms-contentful/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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",

0 commit comments

Comments
 (0)