new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Next.js App Router · all subjects

app-router/proxy

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Proxy matcher config

The matcher config allows you to filter Proxy to run on specific paths. The matcher property in the config object determines which routes the proxy function applies to.

What Proxy does

Proxy allows you to run code before a request is completed. Based on the incoming request, you can modify the response by rewriting, redirecting, modifying request or response headers, or responding directly.

Proxy export options

You can export your proxy function as either a default export or a named proxy export. Both forms are valid: export function proxy(request: NextRequest) or export default function proxy(request: NextRequest).

Proxy basic example

Example showing a basic proxy that redirects requests from /about to /home: ```ts filename="proxy.ts" 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*', } ```

Proxy use cases

Common scenarios where Proxy is effective include: modifying headers for all pages or a subset of pages, rewriting to different pages based on A/B tests or experiments, and programmatic redirects based on incoming request properties.

When to use Proxy vs redirects config

For simple redirects, consider using the redirects configuration in next.config.ts first. Proxy should be used when you need access to request data or more complex logic.

Proxy is not for data fetching

Proxy is not intended for slow data fetching. While Proxy can be helpful for optimistic checks such as permission-based redirects, it should not be used as a full session management or authorization solution.

Caching disabled in Proxy

Using fetch with options.cache, options.next.revalidate, or options.next.tags has no effect in Proxy.

Exclude metadata files from proxy matcher configuration

When using metadata files along with proxy.ts, configure the matcher to exclude the metadata files.

Proxy file for server-side logic

A Proxy is a file (proxy.js) that runs code on the server before request is completed. It is used to implement server-side logic like logging, redirects, and rewrites. Proxy was formerly known as Middleware.

Give your agent this brain