feat: 接入预览模式(Next.js Draft Mode)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user