More unique IPs than any network on the planet, in the world's largest residential pool. That's Shifter.More unique IPs than any network, in the world's largest pool. That's Shifter.

See the numbers

CORS Proxy, Next.js Proxy and JavaScript Proxy Explained

A CORS proxy, the Next.js proxy file and the JavaScript Proxy object are three different things. What each one does, with short code examples.

Engineering · Updated December 3, 2026 · 4 min read
fetch(){ price: 42 }APICORSproxyAccess-Control-Allow-Origin
The direct request is blocked. The blue proxy adds the header the browser asks for.
Knowledge
On this page
  1. CORS proxy
  2. Next.js proxy
  3. JavaScript Proxy object
  4. When you need a network proxy instead

In JavaScript, “proxy” can mean three things. A CORS proxy is a server that fetches an API for your web page. The Next.js proxy is a file that runs before a request reaches your route. The Proxy object wraps another object in your code. None of them changes the IP address your visitors or scrapers use, which is the job of a network proxy such as residential proxies.

What it isWhere it runsUse it to
CORS proxyA small serverYour backendRead an API that browsers block
Next.js proxyA proxy.ts fileYour Next.js serverRedirect, rewrite or check requests
JavaScript ProxyA built-in objectInside your codeControl access to an object
Network proxyA server with its own IPOutside your appSend requests from another address

CORS proxy

A browser does not let a page read a response from another origin unless that server allows it. When the permission is missing, Chrome prints this:

Access to fetch at 'http://127.0.0.1:4701/price' from origin
'http://127.0.0.1:4703' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested resource.

Only browsers enforce this rule. A server can request the same address freely, so a CORS proxy makes the request for you and adds the missing header. This one runs on Node.js without any packages:

import http from 'node:http';

const TARGET = 'https://api.example.com';
const ALLOWED = 'https://www.example.com';

http.createServer(async (req, res) => {
  const headers = {
    'Access-Control-Allow-Origin': ALLOWED,
    'Access-Control-Allow-Methods': 'GET, OPTIONS',
    'Access-Control-Allow-Headers': 'Content-Type',
    Vary: 'Origin',
  };
  if (req.method === 'OPTIONS') { res.writeHead(204, headers); return res.end(); }
  if (req.method !== 'GET') { res.writeHead(405, headers); return res.end(); }

  const url = new URL(req.url, TARGET);
  if (url.origin !== TARGET) { res.writeHead(400, headers); return res.end(); }

  const upstream = await fetch(url);
  res.writeHead(upstream.status, {
    ...headers,
    'Content-Type': upstream.headers.get('content-type') ?? 'text/plain',
  });
  res.end(await upstream.text());
}).listen(3001, '127.0.0.1');

We ran this code with local addresses in Chrome. The direct request failed with the error above, and the same request through the proxy returned the data. Before using it for real, add error handling, a timeout and a rate limit.

The fixed TARGET matters. A proxy that fetches any address it is given can be used by strangers to reach other sites, or private systems on your own network. The same goes for public CORS proxies: their operator can read everything you send, so never pass keys or customer data through one.

If you control the API, you need no proxy at all. Send the Access-Control-Allow-Origin header from the API itself.

Next.js proxy

Next.js uses the word for two separate features.

The proxy.ts file runs on the server before a route is rendered. It was called middleware until Next.js 16, which deprecated the old name. Put it next to your app or pages folder:

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

export function proxy(request: NextRequest) {
  return NextResponse.redirect(new URL('/home', request.url));
}

export const config = { matcher: '/about/:path*' };

Set a matcher. Without one, the file runs on every request, including images and scripts. To move an older project over, Next.js offers a command:

npx @next/codemod@canary middleware-to-proxy .

Rewrites forward a path to another server. The browser only talks to your own domain, so no CORS error appears:

// next.config.js
module.exports = {
  async rewrites() {
    return [
      { source: '/api/shop/:path*', destination: 'https://api.example.com/:path*' },
    ];
  },
};

For most Next.js projects this replaces a separate CORS proxy. If the API needs a secret key, use a route handler, so the key stays on the server. Both features are forms of a reverse proxy, and our post on forward and reverse proxies explains that difference.

JavaScript Proxy object

Proxy is part of the language. It wraps an object and runs your function when a property is read, written or deleted:

const prices = new Proxy({ us: 10 }, {
  get: (target, key) => (key in target ? target[key] : 'not set'),
});

console.log(prices.us); // 10
console.log(prices.de); // not set

Common uses are default values, validation, logging and change tracking. Vue 3, for example, builds its reactive objects on it. Each access goes through your function, so avoid it in code that runs millions of times.

When you need a network proxy instead

A CORS proxy sends every request from your server’s IP address. If the target site limits that address or shows different content by country, changing headers will not help. Route the server’s requests through a proxy with the location you need. Our guide to residential proxies in Node.js has the code.

Frequently asked questions

What is a CORS proxy?

It is a server that requests an API for your web page and returns the response with the Access-Control-Allow-Origin header, so the browser lets your code read it.

Does mode: 'no-cors' fix a CORS error?

No. The request is sent, but the browser gives your code an opaque response with status 0 and an empty body. You cannot read the data.

Is middleware gone in Next.js?

Next.js 16 deprecated the middleware file and renamed it to proxy. The file is now proxy.ts or proxy.js, and the exported function is called proxy.

Is the JavaScript Proxy object a network proxy?

No. It wraps an object in your code and lets you control what happens when someone reads or changes its properties. It sends nothing over the network.

Ready to get started?

Try Shifter's residential proxies, 205M+ IPs, 195+ countries, from $0.10/GB.

Get Started