routing-middleware

Configure Vercel Routing Middleware for request interception, rewrites, redirects, and geo-personalization.

Updated Aug 21, 2025
One-click install
npx skills add https://github.com/Adithiya-S/AI-Study-Companion --skill routing-middleware-adithiya-s
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: routing-middleware
Source: https://github.com/Adithiya-S/AI-Study-Companion/tree/main/.agents/skills/routing-middleware
Command: npx skills add https://github.com/Adithiya-S/AI-Study-Companion --skill routing-middleware-adithiya-s

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Intercepting and modifying HTTP requests before they hit the cache or application code is confusing across frameworks, and developers often mix up Vercel Routing Middleware, Next.js proxy.ts, and Edge Functions. This Skill provides authoritative guidance on implementing platform-level request interception correctly. ## Core Features & Use Cases - Request Interception Guidance: Implement middleware.ts with Edge, Node.js, or Bun runtimes for rewrites, redirects, and header injection before the cache layer. - Middleware Disambiguation: Clarifies the differences between Vercel Routing Middleware, Next.js 16 proxy.ts, and Edge Functions, including the middleware-to-proxy migration path. - Routing Configuration: Covers matcher patterns, project-level routes, bulk redirects, and programmatic vercel.ts configuration via @vercel/config. - Use Case: You want to A/B test two homepage variants based on a global config flag. Use this Skill to write middleware that reads the experiment value and rewrites the request path transparently. ## Quick Start Ask the assistant to write a Vercel middleware.ts file that rewrites requests based on the visitor's country using geolocation.

Frequently Asked Questions about routing-middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Vercel Routing Middleware for rewrites and redirects?

Create a middleware.ts file at the project root with a default exported function that returns rewrite() or redirect responses. Use the config.matcher export to scope which paths trigger the middleware, and import helpers like rewrite and geolocation from @vercel/functions.

What is the difference between Vercel middleware.ts and Next.js proxy.ts?

Vercel Routing Middleware (middleware.ts) is a platform feature working with any framework on Edge, Node.js, or Bun runtimes. Next.js 16 renamed its middleware.ts to proxy.ts, which runs only on the Node.js runtime and sits at the network boundary for Next.js apps.

Does Vercel middleware support the Bun runtime?

Yes, add bunVersion to vercel.json and set the middleware runtime to nodejs; Bun transparently replaces the Node.js runtime. Bun support is in Public Beta and works with Next.js, Express, Hono, and Nitro.

How do I limit middleware to specific routes with matcher?

Export a config object with a matcher property containing path patterns like '/dashboard/:path*' or regex exclusions. Unmatched paths skip middleware invocation entirely, which saves compute on every request.

When should I not use Vercel Routing Middleware?

Avoid it for heavy business logic, database queries, or as the sole auth layer. Use proxy.ts for full Node.js APIs in Next.js, Edge Functions for general edge compute, and Bulk Redirects for thousands of static redirects.