Skip to content

Commit

Permalink
feat: add contentful sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
malewis5 committed Jun 6, 2024
1 parent 31eedcd commit 7d3bdf3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
23 changes: 1 addition & 22 deletions examples/cms-contentful/app/api/draft/route.ts
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";
1 change: 1 addition & 0 deletions examples/cms-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"@contentful/rich-text-react-renderer": "^15.17.1",
"@contentful/rich-text-types": "^16.2.1",
"@contentful/vercel-nextjs-toolkit": "latest",
"@tailwindcss/typography": "0.5.9",
"@types/node": "^20.5.0",
"@types/react": "^18.2.20",
Expand Down

0 comments on commit 7d3bdf3

Please sign in to comment.