feat: 接入预览模式(Next.js Draft Mode)

This commit is contained in:
2026-08-07 15:34:59 +08:00
parent 1abadd04b8
commit 2457d5ec69
9 changed files with 203 additions and 6 deletions
+18
View File
@@ -0,0 +1,18 @@
import { NextRequest, NextResponse } from "next/server";
import { draftMode, cookies } from "next/headers";
import {
PREVIEW_CONTENT_TYPE_COOKIE,
PREVIEW_TOKEN_COOKIE,
} from "@/services/preview.service";
/** 退出预览模式:关闭 Draft Mode 并清除预览专用 cookie,重定向回首页。 */
export async function GET(request: NextRequest) {
const draft = await draftMode();
draft.disable();
const cookieStore = await cookies();
cookieStore.delete(PREVIEW_CONTENT_TYPE_COOKIE);
cookieStore.delete(PREVIEW_TOKEN_COOKIE);
return NextResponse.redirect(new URL("/", request.url));
}