mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
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]>
17 lines
339 B
TypeScript
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,
|
|
})
|
|
}
|