Configure Preview Routes
Preview routes in Next.js
Implement preview mode using two API routes.
If you're using the Basic Starter, preview routes are already created for you.
/pages/api/preview.ts
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
pages/api/exit-preview.ts
import { NextApiResponse } from "next"
export default function exit(_, response: NextApiResponse) { response.clearPreviewData() response.writeHead(307, { Location: "/" }) response.end()}