Skip to main content
The next/server module provides Web-standard request/response wrappers and middleware utilities that work across runtimes (Node.js, Cloudflare Workers, Deno).

Import

NextRequest

Extends the standard Request with Next.js-specific conveniences.

Constructor

URL | RequestInfo
required
URL string, URL object, or Request object.
RequestInit
Standard Request options (method, headers, body, etc.).

Properties

NextURL
Enhanced URL object with pathname helpers.
RequestCookies
Read-only cookie accessor.
string | undefined
Client IP address (from trusted headers).Priority:
  1. CF-Connecting-IP (Cloudflare)
  2. X-Real-IP
  3. X-Forwarded-For (first entry)
GeoData | undefined
Geolocation data (platform-dependent).
Available fields:
  • country?: string — ISO country code
  • city?: string
  • region?: string — State/province
  • latitude?: string
  • longitude?: string

Usage Example

NextResponse

Extends the standard Response with Next.js middleware helpers.

Constructor

Static Methods

<T>(body: T, init?: ResponseInit) => NextResponse<T>
Create a JSON response.
(url: string | URL, status?: number) => NextResponse
Create a redirect response.
(destination: string | URL, init?) => NextResponse
Rewrite to a different URL (proxy pattern).
The client sees the original URL; the server fetches from the destination.
(init?: MiddlewareResponseInit) => NextResponse
Continue to the next handler.

Properties

ResponseCookies
Cookie setter for responses.
Methods:
  • set(name, value, options?) — Set a cookie
  • delete(name) — Delete a cookie (sets Max-Age=0)
  • get(name) — Read a cookie (from Set-Cookie headers)
  • getAll() — Read all cookies

Usage Examples

NextURL

Lightweight URL wrapper with pathname helpers.

Properties

string
Full URL string.
string
Protocol + hostname + port (e.g., https://example.com:3000).
string
URL path (e.g., /api/users).
Query string with ? prefix (e.g., ?page=1).
URLSearchParams
URLSearchParams instance for reading/writing query params.
string
Hash fragment with # prefix (e.g., #section-2).

Methods

() => NextURL
Create a copy of the URL.
() => string
Convert to string (same as .href).

NextFetchEvent

Middleware event object (provides waitUntil for background work).
(promise: Promise<any>) => void
Register a promise to keep the runtime alive after the response is sent.Useful for:
  • Logging
  • Analytics
  • Cache warming

Utility Functions

userAgent

Parse User-Agent header.
boolean
Whether the user agent is a known bot/crawler.
{ name?: string; version?: string; major?: string }
Browser information.
{ model?: string; type?: string; vendor?: string }
Device information.
{ name?: string; version?: string }
Operating system information.
vinext’s UA parser is minimal. For production use, install ua-parser-js or similar.

after

Schedule work after the response is sent (Next.js 15+).
In vinext, after() runs as a microtask (best-effort). For guaranteed background execution, use waitUntil in middleware.

connection

Signal that the response requires a live connection (opt out of ISR).
Sets Cache-Control: no-store and bypasses ISR caching.

Middleware Type

Returning null, undefined, or void is equivalent to NextResponse.next().

Runtime Compatibility

All APIs use Web-standard primitives and work across:
  • Node.js (18+)
  • Cloudflare Workers
  • Deno
  • Vercel Edge Runtime
  • Any WinterCG-compatible runtime

Source

View source code → Implementation: /home/daytona/workspace/source/packages/vinext/src/shims/server.ts