Preview API
Route: /api/preview
File:
apps/ui/src/app/api/preview/route.ts
This route is used by Strapi preview links.
It:
- Validates
secretagainstSTRAPI_PREVIEW_SECRET. - Enables or disables Next.js
draftMode(). - Rewrites the
__prerender_bypasscookie withsameSite: "none". - Redirects to the requested localized URL.
The sameSite: "none" cookie rewrite is required for Strapi's iframe-embedded preview. Without it, draft mode may silently fall back to published content.
Secret required
Preview requests return an error unless STRAPI_PREVIEW_SECRET is configured and the secret query param matches it.
Draft mode
Draft previews depend on Next.js draft mode cookies. The route adjusts the draft-mode cookie so preview can work inside Strapi's iframe preview flow.
Expected query params:
| Param | Purpose |
|---|---|
secret | Must match STRAPI_PREVIEW_SECRET. |
url | Page URL to open. |
status | draft or published; defaults to published. |
locale | Frontend locale; falls back to the default locale. |
Related docs: