Skip to Content

Routing Middleware

all plans


{

"entrypoint":"proxy.ts"


Your entrypoint exports the handler as a default export:


"proxy": {

You can use Routing Middleware with any framework. To add a Routing Middleware to your app, point the proxy property in vercel.json at your entrypoint:

exportdefaultfunctionproxy(request:Request) {


}

status:302,

// Redirect old paths

returnnewResponse(null, {

TypeScript

consturl=newURL(request.url);

});

}

// Continue to next handler

returnnewResponse('Hello from your Middleware!');

if (url.pathname ==='/old-page') {

headers: { Location:'/new-page' },

runtime:'nodejs',

The entrypoint can live in a subdirectory, such as src/proxy.ts. Add proxy.matcher to limit which paths run your Routing Middleware.

exportdefaultfunctionmiddleware(request:Request) {

TypeScript

}

};

exportconstconfig= {

You can also create a middleware.ts file at your project's root directory and skip vercel.json:

returnnewResponse('Hello from your Middleware!');

Next.js proxy documentation for details.

middleware.ts file should be at the same level as your app or pages directory (even if you're using a src directory). See the Quickstart guide for more information.


Logging

Routing Middleware has full support for the console API, including time, debug, timeEnd. Logs will appear inside your Vercel project by clicking View Functions Logs next to the deployment.

Using a database with Routing Middleware

If your Routing Middleware depends on a database far away from one of our supported regions, the overall latency of API requests could be slower than expected, due to network latency while connecting to the database from an edge region. To avoid this issue, use a global database. Vercel has multiple global storage products, including Global Config and Vercel Blob. You can also explore the storage category of the Vercel Marketplace to learn which option is best for you.

Limits on requests

Name

Maximum URL length

14 KB

Routing Middleware is available on the Node.js, Bun, and Edge runtimes. An entrypoint set through the proxy property runs on Node.js.

Limit

4 MB

Maximum request body length

Maximum request headers length

Maximum number of request headers

The following limits apply to requests processed by Routing Middleware:

64

16 KB

With the middleware.ts file convention, the default runtime is Edge. You can change the runtime to Node.js by exporting a config object with a runtime property in your middleware.ts file.

Next.js proxy documentation for details.

To use the Bun runtime, set bunVersion in your vercel.json file and your runtime config to nodejs.

Pricing

Routing Middleware is priced using the fluid compute model, which means you are charged by the amount of compute resources used by your Routing Middleware. See the fluid compute pricing documentation for more information.

Observability

The Vercel Observability dashboard provides visibility into your routing middleware usage, including invocation counts and performance metrics. You can get more insights with Observability Plus:

More resources

Last updated August 14, 2026

Learn more about Routing Middleware by exploring the following resources:

Cross-link map: Routing Middleware (/docs/routing-middleware)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesGetting Started with Routing Middleware — Learn how you can use Routing Middleware, code that executes before a request is processed on a site, to provide speed aVercel Edge Middleware: Dynamic at the speed of static (historical)Routing — Learn how Vercel's CDN routes requests through firewall, project routes, and deployment routes before reaching your applRouting Middleware API — Learn how you can use Routing Middleware, code that executes before a request is processed on a site, to provide speed aReact Router on Vercel — Deploy React Router applications with SSR or SPA mode, then configure the Vercel preset, streaming, caching, and analytiThis page links to (16)Fluid compute — Learn about fluid compute, an execution model for Vercel Functions that provides a more flexible and efficient way to ruFrameworks on Vercel — Vercel supports a wide range of the most popular frameworks, optimizing how your application builds and runs no matter wRuntimes — Runtimes transform your source code into Functions, which are served by our CDN. Learn about the official runtimes suppoUsing the Bun Runtime with Vercel Functions — Learn how to use the Bun runtime with Vercel Functions to create fast, efficient functions.Edge Runtime — Learn about the Edge runtime, an environment in which Vercel Functions can run.Using the Node.js Runtime with Vercel Functions — Learn how to use the Node.js runtime to create functions and deploy Node.js servers on Vercel.Fluid compute pricing — Learn about usage and pricing for fluid compute on Vercel.Vercel Global Config — A Global Config is a global data store that enables experimentation with feature flags, A/B testing, critical redirects,Observability — Find production errors, capture request traces, and discover queryable metrics with Vercel Observability and Vercel CLI.Observability Insights — List of available data sources that you can view and monitor with Observability on Vercel.Observability Plus — Learn about using Observability Plus and its limits.Static Configuration with vercel.json — Learn how to use vercel.json to configure and override the default behavior of Vercel from within your project.Global network and regions — View the list of regions supported by Vercel's CDN and learn about our global infrastructure.Routing Middleware API — Learn how you can use Routing Middleware, code that executes before a request is processed on a site, to provide speed aGetting Started with Routing Middleware — Learn how you can use Routing Middleware, code that executes before a request is processed on a site, to provide speed aVercel Blob — Vercel Blob is a scalable, cost-effective object storage service with private and public access modes for files up to 5Pages that link here (116)By site: vercel-changelog (27) · vercel-kb (36) · vercel-web (22) · vercel-docs (31)From vercel-changelogAdvanced Remix integration with streaming SSR and multi-runtime supportEdge Config is now generally available Edge Function metrics now available in MonitoringEdge Functions are now available in Public BetaEdge Functions are now generally availableEdge Middleware and Edge Functions are now powered by Vercel FunctionsEnhanced geolocation information for Vercel FunctionsHydrogen 2 projects can now be deployed with zero configurationHydrogen projects can now be deployed with zero configurationImproved Node.js compatibility for Edge Middleware and Edge FunctionsImproved performance for Vercel Postgres from Edge FunctionsImprovements and fixesIntroducing the Runtime Cache APIIP Geolocation now available for all plansImprovements and fixesMore flexible Environment Variables in Edge Functions and MiddlewareNew build and deploy capabilities in Vercel CLINew execution duration limit for Edge FunctionsNext.js 13.4 on VercelOpenAI will not support the Hong Kong region (hkg1) for FunctionsVercel Edge Functions can now be regional or globalRun scheduled jobs with Vercel Cron Jobs and Vercel FunctionsSupport for Remix v2Vercel CLI v28 is now availableVercel Cron Jobs are now generally availableVercel Edge Functions are now in public betaVercel Python SDK is now available in betaFrom vercel-kbA/B Testing on Vercel — Learn best practices for A/B testing on VercelAdding a response header — Learn how to add a response header in your Middleware.Build with an Express starter template — Deploy an Express app to Vercel from a template. Browse Express starters from Vercel and the community, then run them loBuild with a FastAPI starter template — Browse FastAPI starter templates for Vercel and deploy one in a few steps. Compare minimal, AI, agent, and full-stack FaBuild with a Flask starter template — Deploy a Flask app to Vercel from a starter template. Compare the Flask Hello World starter, AI SDK, alt text generator,Build with a Hono starter template — Deploy a Hono app to Vercel from a starter template. Compare the Hono API starter, MCP server, AI SDK, Slack Bolt, Next.Can I get a fixed IP address for my Vercel deployments? — Vercel deployments use dynamic IPs by default. Learn how Static IPs, Secure Compute, and AWS PrivateLink give you a fixeHow to add per-request CSP nonces to CDN-cached HTML on Vercel — Use Routing Middleware and a self-fetch to add a fresh CSP nonce to cached HTML without rendering the page again on everFiltering query parameters — Learn how to filter query parameters in your Middleware.How can I increase the limit of redirects or use dynamic redirects on Vercel? — Instructions on how to use Serverless Functions to handle redirects on Vercel.How can I allowlist IP addresses for a deployment? — Vercel deployments use dynamic outbound IPs by default. Learn how to allowlist IP addresses for a deployment with StaticHow to enable CORS on Vercel — Learn how to enable CORS on Vercel with vercel.json, Routing Middleware, framework config, and route handlers, plus howHow to migrate from Fastly to Vercel with zero downtime — Consolidate your CDN infrastructure on Vercel to reduce latency, simplify your configuration, and improve your developerHow to Optimize Next.js + Sitecore JSS — This guide covers performance and usage considerations when building and deploying your Next.js and Sitecore JSS applicaHow can I make my library compatible with the Vercel Edge Runtime? — Learn how to make your library or SDK compatible with the Edge Runtime for existing Edge Runtime code and Routing MiddleMigrate a TanStack Start app from Netlify to Vercel — Move your TanStack Start app off Netlify and onto Vercel Functions, where Fluid compute scales it automatically. Swap toMigrate to Vercel from Cloudflare — Migrate your website's configuration from Cloudflare Pages or Workers to VercelMigrate to Vercel from Netlify — Migrate your website's configuration from Netlify to VercelModifying request headers — Learn how to modify request headers in your Middleware.Troubleshoot and optimize Active CPU usage on Fluid compute — Diagnose which routes drive Active CPU usage and learn to optimize it. Separate traffic growth from per-request CPU workPublish and subscribe to realtime data on Vercel — Learn how to publish and subscribe to realtime data on Vercel with WebSockets, SSE, Redis, and Queues, and when a manageRendering content based on device — Learn how to render different content based on the user agent in your Middleware.Can I use SMTP with Vercel? — Vercel Functions can open SMTP connections on the Node.js runtime. Learn which ports are open, why you must await the seHow to ship an Elysia app on Vercel — Deploy a Elysia app to Vercel with zero configuration. Learn how to ship from a template, the Vercel CLI, or Git, and coHow to ship an Express app on Vercel — Deploy an Express app to Vercel with zero configuration. Configure response streaming, middleware, cron jobs, the Bun ruHow to ship a FastAPI app on Vercel — Deploy a FastAPI app to Vercel with zero configuration. Learn how the Python runtime, Vercel Functions, streaming, middlHow to ship a Fastify app on Vercel — Deploy a Fastify app to Vercel with zero configuration, then add streaming, lifecycle hooks, cron jobs, and observabilitHow to ship a Flask app on Vercel — Deploy a Flask app to Vercel with zero configuration. Learn how to ship from a template, the Vercel CLI, or Git, and conHow to ship an H3 app on Vercel — Deploy an H3 app to Vercel with zero configuration. Learn to configure streaming, middleware, cron jobs, the Bun runtimeHow to ship a Hono app on Vercel — Deploy a Hono app to Vercel with zero configuration. Learn how to ship from a template, the Vercel CLI, or Git, and confHow to ship a Koa app on Vercel — Deploy a Koa app to Vercel with zero configuration. Learn how to ship from the Vercel CLI or Git, and configure responseHow to ship a NestJS app on Vercel — Deploy a NestJS app to Vercel with zero configuration. Learn how to ship from a template, the Nest CLI, or Git, and confUsing the crypto Web API to redirect requests with a unique token — Learn how to use the Crypto Web API in your Middleware.Using xmcp with Next.js — Add an MCP server to an existing Next.js app with xmcp. Create typed tools, add authentication, and deploy to Vercel asVercel vs Netlify — A detailed guide to Vercel vs Netlify: runtimes, compute architecture, AI infrastructure, security, and when to choose eVercel vs Northflank — A detailed guide to Vercel vs Northflank: Fluid compute, CDN and caching, container image functions, security defaults,From vercel-webBehind the scenes of Vercel's infrastructure: Achieving optimal scalability and performanceBillions of dollars, billions of requests: Black Friday-Cyber Monday 2024Announcing the Build Output APIBuild your own web frameworkIntroducing Edge Config: Globally distributed, instant configurationEdge Config: Ultra-low latency data at the edgeVercel Edge Functions are now generally availableNew features for SvelteKit: Optimize your application with easeFlags as code in Next.jsIntroducing support for WebAssembly at the EdgeIntroducing the Vercel AI SDKRegional execution for ultra-low latency rendering at the edgeReleasing safe and cost-efficient blue-green deploymentsThe user experience of the Frontend CloudTransforming customer support with AI: How Vercel decreased tickets by 31%Using SvelteKit 1.0 on VercelUsing the latest Next.js 12.3 features on VercelReplacing Google Optimize with the Vercel Edge NetworkVercel Edge Middleware: Dynamic at the speed of static (historical)Vercel Flags: Platform-native feature flagsRemix without limits (historical)How to build zero-CLS A/B tests with Next.js and Vercel Edge ConfigFrom vercel-docsAlerts — Get notified when something's wrong with your Vercel projects. Set up alerts through Slack, webhooks, or email so you cavercel dev — Learn how to replicate the Vercel deployment environment locally and test your Vercel Project before deploying using theFrameworks on Vercel — Vercel supports a wide range of the most popular frameworks, optimizing how your application builds and runs no matter wElysia on Vercel — Build fast TypeScript backends with Elysia and deploy to Vercel. Learn the project structure, plugins, middleware, and hHono on Vercel — Deploy Hono applications to Vercel with zero configuration. Learn about observability, ISR, and custom build configuratiFrontends on Vercel — Vercel supports a wide range of the most popular frontend frameworks, optimizing how your application builds and runs noAstro on Vercel — Deploy Astro sites to Vercel and configure server-side rendering, ISR, Web Analytics, Image Optimization, and Routing MiFull-stack frameworks on Vercel — Vercel supports a wide range of the most popular backend frameworks, optimizing how your application builds and runs noNext.js on Vercel — Vercel is the native Next.js platform, designed to enhance the Next.js experience.Supported Frameworks on Vercel — Learn about the frameworks that can be deployed to Vercel.Configuring regions for Vercel Functions — Learn how to configure regions for Vercel Functions.Using the Bun Runtime with Vercel Functions — Learn how to use the Bun runtime with Vercel Functions to create fast, efficient functions.Using WebAssembly \(Wasm\) — Learn how to use WebAssembly \(Wasm\) to enable low-level languages to run on Vercel Functions and Routing Middleware.How requests flow through Vercel — Learn how Vercel routes, secures, and serves requests from your users to your application.Vercel Global Config — A Global Config is a global data store that enables experimentation with feature flags, A/B testing, critical redirects,Getting started with Global Config — Learn how to create a Global Config store and read from it in your project.Using Global Config with Statsig — Learn how to use Global Config with Vercel's Statsig integration.Incremental Migration to Vercel — Learn how to migrate your app or website to Vercel with minimal risk and high impact.Runtime Logs — Learn how to search, inspect, and share your runtime logs with the Logs tab.Secure Compute — Secure Compute provides dedicated private networks with VPC peering for Enterprise teams.Static IPs — Access IP-restricted backend services through shared static egress IPs for Pro and Enterprise teams.Account Plans on Vercel — Learn about the different plans available on Vercel.Multi-Project Platforms Quickstart — Programmatically host code for user-generated or AI-generated applications on Vercel.Calculating usage of resources — Understand how Vercel measures and calculates your resource usage based on a typical user journey.Static Configuration with vercel.json — Learn how to use vercel.json to configure and override the default behavior of Vercel from within your project.Programmatic Configuration with vercel.ts — Define your Vercel configuration in vercel.ts with @vercel/config for type-safe routing and build settings.Getting Started with Routing Middleware — Learn how you can use Routing Middleware, code that executes before a request is processed on a site, to provide speed aProject-Level Routing Rules — Add redirects, rewrites, headers, and status codes to your project from the dashboard or API, without deploying new codeRedirects — Learn how to use redirects on Vercel to instruct Vercel's platform to redirect incoming requests to a new URL.Service bindings — Call one service from another using caller-declared service bindings.Skew Protection — Learn how Vercel's Skew Protection ensures that the client and server stay in sync for any particular deployment.

Next

Previous

  • Analyze invocations by request path
  • Break down actions by type, such as redirects or rewrites
  • View rewrite targets and frequency
  • Use the query builder for custom insights

Fluid Compute

Was this helpful?