Preview Mode

Using preview mode with DrupalClient.


⚠️

The `DrupalClient` is available in `next-drupal ^1.3.0` as experimental.

To implement preview mode:

  1. Set a `previewSecret` on the `DrupalClient`.
  2. Implement preview mode using two API routes.

pages/api/preview.ts

import { NextApiRequest, NextApiResponse } from "next"
import { drupal } from "lib/drupal"
export default async function handler(
request: NextApiRequest,
response: NextApiResponse
) {
return await drupal.preview(request, response)
}

pages/api/exit-preview.ts

import { NextApiResponse } from "next"
export default function exit(_, response: NextApiResponse) {
response.clearPreviewData()
response.writeHead(307, { Location: "/" })
response.end()
}