first commit
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled

This commit is contained in:
Arian Tron
2026-03-10 19:37:31 +03:30
commit 61f56f997c
27684 changed files with 2784175 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
import { draftMode } from 'next/headers'
export async function GET(request: Request) {
;(await draftMode()).disable()
return new Response('Draft mode is disabled')
}

View File

@@ -0,0 +1,23 @@
// route handler with secret and slug
import { draftMode } from 'next/headers'
import { redirect } from 'next/navigation'
// Preview URL: localhost:3000/api/draft?secret=secret-token&slug=preview-page
export async function GET(request: Request) {
// Parse query string parameters
const { searchParams } = new URL(request.url)
const secret = searchParams.get('secret')
const slug = searchParams.get('slug')
// Check the secret and next parameters
if (secret !== 'secret-token' || !slug) {
return new Response('Invalid token', { status: 401 })
}
// Enable Draft Mode by setting the cookie
;(await draftMode()).enable()
// Redirect to the path
redirect(`/${slug}`)
}

View File

@@ -0,0 +1,16 @@
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}

View File

@@ -0,0 +1,6 @@
import { draftMode } from 'next/headers'
export default async function PreviewPage() {
const { isEnabled } = await draftMode()
return <h1>{isEnabled ? 'draft' : 'none'}</h1>
}

View File

@@ -0,0 +1,42 @@
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('app-dir - draft-mode-middleware', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
it('should be able to enable draft mode with middleware present', async () => {
const browser = await next.browser(
'/api/draft?secret=secret-token&slug=preview-page'
)
await retry(async () => {
expect(next.cliOutput).toContain(
'draftMode().isEnabled from middleware: true'
)
})
await browser.loadPage(new URL('/preview-page', next.url).toString())
const draftText = await browser.elementByCss('h1').text()
expect(draftText).toBe('draft')
})
it('should be able to disable draft mode with middleware present', async () => {
const browser = await next.browser('/api/disable-draft')
await retry(async () => {
expect(next.cliOutput).toContain(
'draftMode().isEnabled from middleware: false'
)
})
await browser.loadPage(new URL('/preview-page', next.url).toString())
const draftText = await browser.elementByCss('h1').text()
expect(draftText).toBe('none')
})
})

View File

@@ -0,0 +1,12 @@
import { NextResponse, type NextRequest } from 'next/server'
import { draftMode } from 'next/headers'
export async function middleware(req: NextRequest) {
const { isEnabled } = await draftMode()
console.log('draftMode().isEnabled from middleware:', isEnabled)
return NextResponse.next()
}
export const config = {
matcher: ['/((?!_next/static|_next/image|img|assets|ui|favicon.ico).*)'],
}