
A project routing rule template that rewrites requests under /api to an external origin, letting you proxy API traffic through your domain without code changes or redeployment.
Proxying puts the Vercel CDN in front of your backend, improving performance through Vercel's global edge network and reducing cost with built-in caching. It also adds a layer of security with the Vercel Firewall.
Project level routing rules let you manage routing at the CDN layer without deploying new code. Rules take effect instantly after publishing and can be configured through the Vercel Dashboard, CLI, API, or SDK.
This template creates a rewrite rule that proxies all requests matching /api/:path* to an external backend. This is useful when your API is hosted separately and you want to serve it through your Vercel domain to avoid CORS issues and keep backend URLs hidden from clients.
https://api.example.com/$1 with your actual backend URL.The generated routing rule provides a basic rewrite structure. Consider customizing the following to suit your needs:
/api/:path* to match your specific API paths.CDN-Cache-Control header to cache responses at the edge.Vercel-Cache-Tag header to enable targeted cache purging.vercel routes add "API Proxy" \ --src "/api/:path*" \ --src-syntax path-to-regexp \ --action rewrite \ --dest "https://api.example.com/:path*" \ --yes
vercel routes publish --yesRouting rules can also be configured using the Vercel REST API or the Vercel SDK.
Routing rules can also be defined in your code for version control. See the Proxy requests to external origins template for a code-based approach using vercel.ts.