UNPKG

@prismicio/next

Version:

Helpers to integrate Prismic into Next.js apps

1 lines 1.26 kB
{"version":3,"file":"exitPreview.cjs","sources":["../src/exitPreview.ts"],"sourcesContent":["/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler.\n *\n * @example\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \treturn await exitPreview();\n * }\n * ```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\");\n\n\t(await draftMode()).disable();\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t});\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgBA,eAAsB,cAAW;AAIhC,QAAM,EAAE,UAAA,IAAc,MAAM,OAAO,cAAc;AAEhD,GAAA,MAAM,UAAS,GAAI;AAGb,SAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,IACtD,SAAS;AAAA,MACR,iBAAiB;AAAA,IAAA;AAAA,EACjB,CACD;AACF;;"}