Next.js Middleware and Edge Runtime
Implement middleware and edge-safe logic for request-time controls.
When to Use
- •Auth gating and redirects
- •Geo-based routing
- •Lightweight request processing
Inputs
- •Matchers and paths
- •Redirect/rewrites rules
- •Tenant routing or auth gates
Instructions
- •Add
middleware.tsat the project root. - •Keep logic stateless and edge-safe.
- •Use
matcherconfig to scope routes. - •Avoid Node-only APIs in edge runtime.
- •Resolve tenant or auth context early when required.
Output
- •Middleware with scoped edge-safe behavior.