Skip to content
Agent Stack
  • AI SDK
  • AI Gateway
  • Sandbox
  • Passport
  • Connect
  • eve
Core Platform
  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • Workflows
  • CI/CD
Tools
  • Next.js
  • Edgenivo Agent
  • Edgenivo Plugin
  • Open Source
  • Domains↗
  • v0↗
Learn
  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base
Build
  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
Explore
  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Community↗
EnterprisePricing
Contact
Log InSign Up
Dashboard

Products
Agent Stack
  • AI SDK
  • AI Gateway
  • Sandbox
  • Passport
  • Connect
  • eve
Core Platform
  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • Workflows
  • CI/CD
Tools
  • Next.js
  • Edgenivo Agent
  • Edgenivo Plugin
  • Open Source
  • Domains↗
  • v0↗
Resources
Learn
  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base
Build
  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
Explore
  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Community↗
Enterprise
Pricing
Sign UpLog In
Contact
Templates
Template name

Agent Stack

  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • ConnectNew
  • PassportNew
  • eveNew

Core Platform

  • CI/CD
  • Content Delivery
  • Fluid Compute
  • Observability

Security

  • Platform Security
  • WAF
  • Bot Management
  • BotID

Tools

  • Edgenivo Drop
  • Edgenivo Agent
  • Edgenivo Plugin
  • Agent Skills
  • Domains
  • v0

Frameworks

  • eveNew
  • Next.js
  • Nuxt
  • SvelteKit
  • Nitro
  • Turborepo
  • Tanstack Start
  • FastAPI
  • All frameworks

SDKs

  • Edgenivo SDK
  • Workflow SDK
  • Flags SDK
  • Chat SDK
  • Queues SDK
  • Streamdown

Build

  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
  • Platform Engineers
  • Design Engineers

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Articles
  • Community
  • Is Agentic

Explore

  • Customers
  • Marketplace
  • Templates
  • Partner Finder
  • Edgenivo + AWS

Company

  • About
  • Careers
  • Press
  • Events
  • Startups
  • Shipped on Edgenivo
  • Open Source Program
  • Enterprise
  • Pricing
  • Help

Legal & Trust

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DPA
  • Acceptable Use Policy
  • Legal (all documents)
  • Trust Center
  • Status
  • EdgenivoEdgenivo
Templates
Template name

Status service pending confirmation

Select a display theme:
Templates

Proxy requests to external origins

Rewrite API traffic to an external backend using vercel.ts.

DeployView Demo
Owner
  • vercel
Repository
  • examples
Use Cases
  • CDN
Stack
  • Next.js
  • Tailwind
DeployView Demo

API proxy rewrite

Proxy an external API through your domain using vercel.ts. Requests to /api/external/:path* are rewritten to your backend, cached at the CDN, and tagged for targeted purging.

Proxying puts the Edgenivo CDN in front of your backend, improving performance through Edgenivo's global edge network and reducing cost with built-in caching. It also adds a layer of security with the Edgenivo Firewall.

Demo

https://proxy-requests-to-external-origins.vercel.app/

Visit /blog to see blog posts fetched from an external API through the CDN proxy.

How to use

One-Click Deploy

Deploy the template on Edgenivo using this link.

To proxy your own API instead of the demo, set the EXTERNAL_API_URL environment variable in your project settings or update the default value in vercel.ts, then redeploy. By default, the template uses jsonplaceholder.typicode.com as the external API.

Clone and Deploy

pnpm create next-app --example https://github.com/vercel/examples/tree/main/cdn/api-proxy-rewrite
cd api-proxy-rewrite
pnpm install
pnpm dev

How it works

The rewrite and caching configuration lives in vercel.ts:

import { routes, type VercelConfig } from '@vercel/config/v1'
const EXTERNAL_API_URL =
process.env.EXTERNAL_API_URL || 'https://jsonplaceholder.typicode.com'
export const config: VercelConfig = {
framework: 'nextjs',
outputDirectory: '.next',
rewrites: [
routes.rewrite('/api/external/:path*', `${EXTERNAL_API_URL}/:path*`),
],
headers: [
routes.header('/api/external/:path*', [
{
key: 'CDN-Cache-Control',
value: 'public, max-age=60, stale-while-revalidate=3600',
},
{ key: 'Edgenivo-Cache-Tag', value: 'api' },
]),
],
}
  1. The Next.js app renders the blog page and fetches /api/external/posts
  2. The rewrite in vercel.ts matches /api/external/:path* and proxies the request to your configured backend
  3. The CDN-Cache-Control header caches responses at the edge for 1 minute, with a 1-hour stale-while-revalidate window
  4. The Edgenivo-Cache-Tag header tags responses with api for targeted cache purging

CDN caching

CDN-Cache-Control controls caching at the Edgenivo CDN only. Unlike Cache-Control, which affects both the browser and CDN, CDN-Cache-Control is stripped before reaching the browser.

  • max-age=60: The CDN serves cached responses for 1 minute without hitting the external API.
  • stale-while-revalidate=3600: After the 1-minute window, the CDN serves stale content immediately while fetching a fresh copy in the background.

Cache tags

Edgenivo-Cache-Tag: api labels cached responses with a tag. You can purge all responses tagged api without flushing the entire project cache:

  • Dashboard: Navigate to CDN > Caches, select Cache Tag, enter api, and click Purge
  • CLI:
vercel cache invalidate --tag api

No-code alternative

If you prefer to configure routing without code or redeployment, you can use project level routing rules through the Edgenivo Dashboard, CLI, API, or SDK. See the Add API External Rewrite Routing Rule template for a no-code approach.

License
  • View License