t3-code-android-nightly/.repos/alchemy-effect/examples/cloudflare-website-vinext/proxy.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

28 lines
838 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import {
timezoneFromRequest,
visitorTimezoneHeader,
} from "./src/VisitorTimezone.ts";
/**
* Next.js 16 / vinext `proxy.ts` (the `middleware.ts` file convention
* is deprecated). Trimmed to the routes this Alchemy example ships.
*/
export function proxy(request: NextRequest) {
if (request.nextUrl.pathname === "/admin") {
return new Response("Blocked by proxy", { status: 403 });
}
const requestHeaders = new Headers(request.headers);
requestHeaders.set(visitorTimezoneHeader(), timezoneFromRequest(request));
const response = NextResponse.next({
request: { headers: requestHeaders },
});
response.headers.set("x-mw-ran", "true");
return response;
}
export const config = {
matcher: ["/", "/notes", "/use-cache", "/api/:path*", "/admin"],
};