Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Next.js Edge Middleware example that reads a cookie at the edge and rewrites visitors to a statically generated page based on its value.

Minimal Flask example that runs a WSGI Python API on Vercel Serverless Functions using the Python Runtime.

Vercel example boilerplate that runs an AI SDK backend on a Hono server and deploys with the Vercel CLI.

A persisted Next.js chat template for eve, built with shadcn/ui, Tailwind CSS, Streamdown, Better Auth, Drizzle, and Neon.

Open-source AI chatbot template built with Next.js, the AI SDK by Vercel, and Groq for streaming chat responses.

Minimal Shopify Hydrogen v2 headless storefront boilerplate built on Remix, ready to deploy to Vercel with zero configuration.
Adding Cookies is a Next.js Edge Middleware example from the Vercel examples repository that reads a cookie on the edge and rewrites the visitor to a statically generated page, so no server-rendering step is needed just to branch on a cookie value.
Adding Cookies is an edge middleware template published inside the vercel/examples monorepo (topics: examples, nextjs, vercel) that reads the beta cookie from an incoming request and rewrites the user to either a /beta or /non-beta statically generated page. It takes an HTTP request as input, parses the cookie value with NextRequest's cookie API, mutates the URL pathname, and returns a rewrite response via NextResponse.rewrite() — all before the page is served. It runs on Next.js Edge Middleware and deploys to Vercel, and the code lives primarily in a single middleware.ts file written with the next/server imports NextRequest and NextResponse.
req.cookies.get('beta'), JSON-parses the value, and falls back to false when the cookie is missing or unset.NextResponse.rewrite() serves the alternate page while keeping the original URL in the browser address bar.config object with matcher: '/' scopes the middleware to the root route only.pnpm create next-app --example followed by pnpm dev.beta cookie at the edge and serve a different static page to opted-in users without touching page-level data fetching.ab-testing-simple template to branch visitors on the edge.middleware.ts file that is easy to copy into an existing app.matcher (the root path).beta cookie and JSON-parses it, defaulting to false.nextUrl.pathname to /beta or /non-beta.NextResponse.rewrite() so the matched static page is served under the same URL.It reads a cookie named beta inside Next.js Edge Middleware and rewrites the request to a /beta or /non-beta statically generated page. The browser URL stays the same, and the decision happens before the page is rendered, so no server-side data fetching is required.
It rewrites, not redirects. NextResponse.rewrite() returns the alternate page content while preserving the original URL, which avoids an extra redirect round-trip and keeps the visitor's address bar unchanged.
Yes. It is an open-source example in the Vercel examples repository, licensed as part of that collection, and you can clone it and deploy it to your own Vercel account at no cost beyond your hosting plan.
Yes. Bootstrap it with pnpm create next-app --example pointing at the edge-middleware cookies example, then run pnpm dev to start Next.js in development mode. The middleware executes locally through the Next.js dev server.
