Configure Preview Routes
Preview routes in Next.js
If you're using the Basic Starter, preview routes are already configure for you.
To implement preview mode:
- Set a
`previewSecret`
on the`DrupalClient`
. This is the same secret used when creating your site on Drupal. - 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()}