Files
Andrew ClarkandGitHub 3ff99bd0e8 Re-implement hmr-refresh in terms of refresh (#87135)
Based on:
- #87134 

---

hmr-refresh-reducer is identical to refresh-reducer except for the fact
that it doesn't evict the prefetch cache. So this refactors both
implementations to call the same shared function.
2025-12-15 18:27:14 -05:00

33 lines
1009 B
TypeScript

import { NextRequest, NextResponse } from 'next/server'
// Simulates what might happen if a proxy or firewall modifies the
// request based on a condition that changes after the prefetch but before
// the actual navigation.
//
// The proxy modifies the request based on special search parameters, but only
// during a navigation — not during a prefetch.
export const config = {
matcher: [
{
source: '/:path*',
// Exclude prefetch requests
missing: [{ type: 'header', key: 'Next-Router-Prefetch' }],
},
],
}
export default function proxy(req: NextRequest) {
const mismatchRedirect = req.nextUrl.searchParams.get('mismatch-redirect')
if (mismatchRedirect) {
// Redirect to the given URL.
return NextResponse.redirect(new URL(mismatchRedirect, req.url))
}
const mismatchRewrite = req.nextUrl.searchParams.get('mismatch-rewrite')
if (mismatchRewrite) {
// Rewrite to the given URL.
return NextResponse.rewrite(new URL(mismatchRewrite, req.url))
}
}