mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This PR updates the `cms-sanity` example to use: - App Router - TypeScript - Sanity Studio v3 instead of v2 - Embeds the Studio inside the next app on the `/studio` route. - ISR / Data Cache (revalidations through `revalidatePath` while in Live Visual Editing, time-based to match the Sanity API CDN in production). - Support Vercel Visual Editing out of the box. - The new `next-sanity/image` component. - Vercel Speed Insights. - The Sanity Presentation Tool for live content previews. - Sanity Portable Text setup to fully support `@tailwindcss/typography`. - [AI Assist](https://www.sanity.io/docs/ai-assist) - Auto fill in `alt` text on images. - Preset prompts for content creation
28 lines
798 B
TypeScript
28 lines
798 B
TypeScript
/**
|
|
* This file is used to allow Presentation to set the app in Draft Mode, which will load Visual Editing
|
|
* and query draft content and preview the content as it will appear once everything is published
|
|
*/
|
|
|
|
import { validatePreviewUrl } from "@sanity/preview-url-secret";
|
|
import { draftMode } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
|
|
import { client } from "@/sanity/lib/client";
|
|
import { token } from "@/sanity/lib/token";
|
|
|
|
const clientWithToken = client.withConfig({ token });
|
|
|
|
export async function GET(request: Request) {
|
|
const { isValid, redirectTo = "/" } = await validatePreviewUrl(
|
|
clientWithToken,
|
|
request.url,
|
|
);
|
|
if (!isValid) {
|
|
return new Response("Invalid secret", { status: 401 });
|
|
}
|
|
|
|
draftMode().enable();
|
|
|
|
redirect(redirectTo);
|
|
}
|