add support for previewing pages

This commit is contained in:
2026-05-19 17:48:33 +02:00
parent f91c67f526
commit a5ebb897f1
25 changed files with 471 additions and 67 deletions
+7
View File
@@ -0,0 +1,7 @@
import { cookies, draftMode } from "next/headers";
export async function POST() {
(await draftMode()).disable();
(await cookies()).delete("preview-token");
return new Response(null, { status: 204 });
}
+25
View File
@@ -0,0 +1,25 @@
import { cookies, draftMode } from "next/headers";
import { redirect } from "next/navigation";
import { NextRequest } from "next/server";
// Wagtail-headless-preview directs the editor's preview iframe here with
// ?content_type=app.Model&token=<signed>. We stash the token in a cookie,
// enable Next.js draft mode, and redirect to the type-dispatching renderer.
export async function GET(req: NextRequest) {
const token = req.nextUrl.searchParams.get("token");
const contentType = req.nextUrl.searchParams.get("content_type");
if (!token || !contentType) {
return new Response("missing token/content_type", { status: 400 });
}
(await draftMode()).enable();
(await cookies()).set("preview-token", token, {
httpOnly: true,
sameSite: "lax",
secure: process.env.NODE_ENV === "production",
maxAge: 60 * 60 * 24,
path: "/",
});
redirect("/preview/render");
}