Edge Middleware is available on all plans
Edge Middleware is code that executes before a request is processed on a site. Based on the request, you can modify the response. Because it runs before the cache, using Middleware is an effective way of providing personalization to statically generated content. Depending on the incoming request, you can execute custom logic, rewrite, redirect, add headers and more, before returning a response.
You can use Edge Middleware with any framework. To add Middleware to your app, you need to create a
middleware.ts file at your project's root directory.
middleware.tsfile should be at the same level as your
pagesdirectory (even if you're using a
srcdirectory). See the Quickstart guide for more information.
Edge Middleware has full support for the
console API, including
timeEnd, etc. Logs will appear inside your Vercel project by clicking View Functions Logs next to the deployment.
If your Edge Middleware depends on a database far away from one of our Edge regions, the overall latency of API requests could be slower than expected. To avoid this issue, use a global database. Vercel has multiple global storage products, including Edge Config, Vercel KV, and Vercel Blob. See our storage docs to learn which option is best for you.
Learn more about Edge Middleware by exploring the following resources:
Deploy an Edge Middleware template
Deploy a project setup with Edge Middleware.
Edge Middleware API
Learn about the available APIs when working with Edge Middleware.
Usage and pricing
Learn about usage and pricing for using Edge Middleware with Vercel.
Learn about the limitations of using Edge Middleware with Vercel.