Skip to main content

Proxy / Middleware

The NextGlobeGen proxy can be enabled in proxy.ts file. The proxy handles locale negotiation and adds alternate links of the page to the response headers.

src/proxy.ts
export { proxy } from "next-globe-gen/proxy";

export const config = {
// Matcher ignoring next internals and static assets
matcher: ["/((?!_next|.*\\.).*)"],
};
Backward Compatibility

For backward compatibility with Next.js 15 and earlier, the middleware export is also available:

export { middleware } from "next-globe-gen/middleware";

Parametersโ€‹

proxy(request: NextRequest, opts?: { skipAlternateLinkHeader?: boolean });
ParamTypeRequiredDescription
requestNextRequestYesThe request that is passed to Next.js middleware function
opts.skipAlternateLinkHeaderboolean-If the alternate link header should be skipped or not (default: false)
opts.localeNegotiation"force" | "skip" | "default"-Modify if the locale negotiation should be skipped or ran forcefully
opts.localeCookieNamestring-Custom locale cookie name (default: "NEXTGLOBEGEN_LOCALE")
opts.localeCookieOptsPartial<ResponseCookie>-Custom locale cookie options

Returnsโ€‹

proxy returns a NextResponse instance, which can be further modified.

With other proxy logicโ€‹

If you need to use custom proxy logic, call the proxy yourself with the given request instance and modify the returned response.

src/proxy.ts
import nextGlobeGenProxy from "next-globe-gen/proxy";

export function proxy(request: NextRequest) {
const response = nextGlobeGenProxy(request);
/**
* Other custom logic that possibly modify the response
*/
return response;
}

export const config = {
// Matcher ignoring next internals and static assets
matcher: ["/((?!_next|.*\\.).*)"],
};