Home
Next.js
Next.js Proxy
Daniel Nguyen
Daniel Nguyen
September 27, 2026
1 min

Table Of Contents

01
What can Proxy do?
02
Use matcher when needed
03
Don't put everything in Proxy

In Next.js 16, middleware.ts was renamed to proxy.ts. The idea is still the same: run code before a request is completed. I usually think of Proxy as a checkpoint between the request and your app:

Request → proxy.ts → Next.js App
Request → proxy.ts → Next.js App

Request → proxy.ts → Next.js route

What can Proxy do?

Proxy can inspect an incoming request and decide what happens next. For example, you can redirect, rewrite URLs, modify headers, or return a response directly. A simple redirect looks like this:

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function proxy(request: NextRequest) {
return NextResponse.redirect(
new URL('/home', request.url)
)
}

Use matcher when needed

You usually don’t want Proxy to run for every route. Use matcher to limit it:

export const config = {
matcher: '/admin/:path*',
}

Now Proxy runs for /admin and nested routes, which is useful for things like checking a cookie before accessing an admin area.

Don’t put everything in Proxy

Proxy is better for lightweight request-level logic such as redirects, rewrites, and quick checks. It shouldn’t become your entire authentication or business-logic layer. Keep the heavy work in your server/API layer.

proxy.ts
→ quick request decision
Server / API
→ business logic

Tags

#NextJS

Share

Daniel Nguyen

Daniel Nguyen

Frontend Developer

Frontend developer specializing in React, Next.js, and JavaScript. Writing practical guides on modern web development at Dev98.

Expertise

React
Next.js
JavaScript
TypeScript
Python

Social Media

githublinkedinyoutubewebsite

Related Posts

Next.js
GSAP in Next.js: A Practical Guide
September 29, 2026
1 min
Dev98

Dev98

React · Next.js · Web development