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.
Preview requests return an error unless STRAPI_PREVIEW_SECRET is configured and the secret query param matches it.
STRAPI_URL must match the admin originThe preview iframe auto-refreshes on save via a postMessage from the Strapi
admin, and StrapiPreviewListener only accepts messages whose origin matches
STRAPI_URL. Locally, http://localhost:1337 and http://127.0.0.1:1337 are
different origins: if STRAPI_URL uses one and you open the admin on the
other, every update message is dropped and the iframe silently stays stale —
nothing is logged. Set STRAPI_URL to the origin you actually browse.
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: