| 1 | import { NextRequest, NextResponse } from "next/server"; |
| 2 | import { |
| 3 | timezoneFromRequest, |
| 4 | visitorTimezoneHeader, |
| 5 | } from "./src/VisitorTimezone.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Next.js 16 / vinext `proxy.ts` (the `middleware.ts` file convention |
| 9 | * is deprecated). Trimmed to the routes this Alchemy example ships. |
| 10 | */ |
| 11 | export function proxy(request: NextRequest) { |
| 12 | if (request.nextUrl.pathname === "/admin") { |
| 13 | return new Response("Blocked by proxy", { status: 403 }); |
| 14 | } |
| 15 | |
| 16 | const requestHeaders = new Headers(request.headers); |
| 17 | requestHeaders.set(visitorTimezoneHeader(), timezoneFromRequest(request)); |
| 18 | |
| 19 | const response = NextResponse.next({ |
| 20 | request: { headers: requestHeaders }, |
| 21 | }); |
| 22 | response.headers.set("x-mw-ran", "true"); |
| 23 | return response; |
| 24 | } |
| 25 | |
| 26 | export const config = { |
| 27 | matcher: ["/", "/notes", "/use-cache", "/api/:path*", "/admin"], |
| 28 | }; |