Files
f749684921 Update cache handling in draft mode (#51663)
Similar to `getStaticProps` when draft mode is enabled we should bypass
the cache so fresh data is shown.

x-ref: [slack
thread](https://vercel.slack.com/archives/C052BQ8F9EJ/p1687440125828479?thread_ts=1684336597.437409&cid=C052BQ8F9EJ)
and
[tweet](https://twitter.com/tomus_sherman/status/1669023879656873988)

---------

Co-authored-by: Steven <[email protected]>
2023-06-22 14:03:11 -07:00

17 lines
339 B
TypeScript

import { draftMode } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server'
export function GET(req: NextRequest) {
const status = req.nextUrl.searchParams.get('status')
if (status === 'enable') {
draftMode().enable()
} else {
draftMode().disable()
}
return NextResponse.json({
status,
})
}