@contentful/vercel-nextjs-toolkit

中文文档
1.6.2发布于 2026/10/15MITTypeScriptESM + CJS零依赖近 30 天下载 1.4万

Contentful helper SDK for Vercel platform app integration to enable live preview

原始使用文档
文档目录11 节
  1. Requirements
  2. Getting Started
  3. Usage
  4. Route handlers for activating Draft Mode
  5. Additional helpful resources
  6. Reach out to us
  7. You have questions about how to use this library?
  8. Found a bug or want to propose a feature?
  9. You need to share confidential information or have other qu…
  10. License
  11. Code of Conduct

Vercel Next.js Toolkit for Contentful

A toolkit of Next.js helpers that make it easier to use Contentful in a Next.js project hosted on Vercel.

This toolkit is intended as a companion to Contentful's Vercel App, a Contentful Marketplace integration that helps your content team get up and running quickly with your Vercel project powered by Contentful.

Requirements

  • Node.js v16 or later
  • Next.js v13 or later

Getting Started

Install the toolkit using npm:

npm install --production @contentful/vercel-nextjs-toolkit

Usage

Route handlers for activating Draft Mode

The toolkit provides convenient route handlers you can export from your application that allow members of your team to activate Draft Mode, enabling them to view unpublished content dynamically in your application.

These handlers leverage Vercel's Protection Bypass for Automation feature to ensure Draft Mode is only accessible when the user is authorized via this feature.

Contentful's Vercel App makes use of these handlers to provide preview URLs that can be used out of the box with Contentful's preview features for content editors.

App Router usage

If your NextJs project is using App Router, create a route.ts or route.js route handler file in a dedicated folder (e.g. api/enable-draft) inside your app directory:

// app/api/enable-draft/route.ts|js

export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router"

Pages Router usage

If your NextJs project is using Pages Router, create an enable-draft.ts or enable-draft.js API route file inside the pages/api directory:

// pages/api/enable-draft.ts|js

export { enableDraftHandler as default } from "@contentful/vercel-nextjs-toolkit/pages-router";

Preview URL output

With these handlers installed aboves, you can construct preview URLs that activate Draft Mode and redirect the user to a desired path in your application.

Because the handlers use Vercel's Protection Bypass for Automation feature, you will to enable Protection Bypass for Automation in your Vercel project and instrument your preview URL with the token secret.

Assuming you had a Next.js application with a route app/blog-posts/[slug].ts, an example preview URL might look like:

https://your-vercel-app.com/api/enable-draft?path=%2Fblog-posts%2Fa-day-in-my-life&x-vercel-protection-bypass=generated-vercel-secret

After verifying that the provided bypass secret matches the secret used in your Vercel project, the handlers above would redirect a user to:

https://your-vercel-app.com/blog-posts/a-day-in-my-life?x-vercel-protection-bypass=generated-vercel-secret&x-vercel-set-bypass-cookie=samesitenone

The values provided in the x-vercel-* query parameters trigger Vercel to set a cookie in a redirect response that allows future requests to bypass the cache and be served dyanmically, with Draft Mode enabled.

[!NOTE]
If you install and configure Contentful's Vercel App, a preview URL similar to the above will be generated dynamically and integrated seamlessly into Contentful's content preview experience for your Contentful users.

Additional helpful resources

  • To be completed

Reach out to us

You have questions about how to use this library?

  • Reach out to our community forum: Contentful Community Forum
  • Jump into our community slack channel: Contentful Community Slack

Found a bug or want to propose a feature?

  • File an issue here on GitHub: File an issue. Make sure to remove any credentials from your code before sharing it.

You need to share confidential information or have other questions?

  • File a support ticket with Contentful Customer Support: File support ticket

License

This repository is published under the MIT license.

Code of Conduct

We want to provide a safe, inclusive, welcoming, and harassment-free space and experience for all participants, regardless of gender identity and expression, sexual orientation, disability, physical appearance, socioeconomic status, body size, ethnicity, nationality, level of experience, age, religion (or lack thereof), or other identity markers.

Read our full Code of Conduct.

版本与发布记录

@contentful/vercel-nextjs-toolkit 共发布 28 个版本,首次发布于 2024/04/26;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.6.2latest2026/10/1526 天前
1.6.12026/07/213 个月前
1.6.02025/04/221.6 年前
1.4.12025/01/081.8 年前
1.3.22024/06/042 年前
1.3.12024/05/072 年前

关于 @contentful/vercel-nextjs-toolkit 的常见问题

@contentful/vercel-nextjs-toolkit 是什么?

Contentful helper SDK for Vercel platform app integration to enable live preview

如何安装 @contentful/vercel-nextjs-toolkit?

在项目目录运行 npm install @contentful/vercel-nextjs-toolkit,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(^14.2.2 || ^15.1.9 || ^16.0.7)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@contentful/vercel-nextjs-toolkit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@contentful/vercel-nextjs-toolkit 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@contentful/vercel-nextjs-toolkit 可以商用吗?

@contentful/vercel-nextjs-toolkit 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@contentful/vercel-nextjs-toolkit 的下载量有多少?

根据 npm 官方下载统计,@contentful/vercel-nextjs-toolkit 在 2026/10/11 – 2026/11/09 这 30 天内被下载 14,069 次,日均约 469 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@contentful/vercel-nextjs-toolkit 还在维护吗?

最新版本 1.6.2 发布于 2026/10/15(26 天前);至今共发布 28 个版本,其中过去 12 个月发布了 2 个;首次发布于 2024/04/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。