Middleware
Run code before a request is processed. Modify headers, rewrite paths, or implement authentication logic at the edge with sub-millisecond latency. Optimize delivery without touching your origin.
Technical Specifications:
Execution Time
Sub-1ms
Runtime
Edge Light (V8)
Latency Added
< 2ms
Capabilities
Headers, Rewrites, Cookies
Scaling
Instant & Automatic
Works seamlessly with:
Example 1
Example 2
Example 3
alt_route
Product Capabilities
Zero Latency
Execute logic before the cache without adding perceptible latency to the request.
Dynamic Routing
Rewrite paths and redirect users based on headers
Bot Protection
Identify and block automated traffic at the edge before it hits your origin.
Experience
Logic at the Edge
Intercept requests before they hit your cache or origin. Perform authentication, A/B testing, or geo-routing instantly.
- Import the 'next' helper from the edge SDK.
- Check the request properties, such as the user's country code.
- Rewrite the URL path to a localized version based on the geography.