19 lines
610 B
TypeScript
19 lines
610 B
TypeScript
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));
|
|
}
|