mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #448] [MERGED] fix: Pages prod config headers and redirects after middleware rewrites #577
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#577
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/448
Author: @JaredStowell
Created: 3/11/2026
Status: ✅ Merged
Merged: 3/11/2026
Merged by: @james-elicx
Base:
main← Head:jstowell/fix-pages-prod-config-matchers-before-middleware-rewrite📝 Commits (8)
772c166Fix headers matching original path07aba4fReview redirect ordering paritybe11d4eFix config redirects order52387feFix dev middleware parity239ba26Fix dev middleware request parity25d4b5bMerge remote-tracking branch 'origin/main' into jstowell/fix-pages-prod-config-matchers-before-middleware-rewrite763c6e0address review: worker header/fallback parity, early-return in attachRouteHandlerMiddlewareContext, cache node request headers, add dev redirect test2be7a82address second-round bonk comments: sanitizeDestination in worker redirect, nodeRequestHeaders comment, app-rsc-entry guard comment, E2E redirect test, updated snapshots📊 Changes
13 files changed (+584 additions, -234 deletions)
View changed files
📝
examples/pages-router-cloudflare/middleware.ts(+19 -1)➕
examples/pages-router-cloudflare/next.config.mjs(+25 -0)📝
examples/pages-router-cloudflare/worker/index.ts(+24 -21)📝
packages/vinext/src/deploy.ts(+30 -27)📝
packages/vinext/src/entries/app-rsc-entry.ts(+38 -15)📝
packages/vinext/src/index.ts(+46 -50)📝
packages/vinext/src/server/prod-server.ts(+31 -27)📝
tests/__snapshots__/entry-templates.test.ts.snap(+229 -91)📝
tests/deploy.test.ts(+11 -2)📝
tests/e2e/cloudflare-pages-router-dev/pages-router.spec.ts(+27 -0)📝
tests/fixtures/pages-basic/middleware.ts(+12 -0)📝
tests/fixtures/pages-basic/next.config.mjs(+14 -0)📝
tests/pages-router.test.ts(+78 -0)📄 Description
Fix Pages Router production ordering so
next.config.jsheaders()andredirects()still match against the original request pathname even when middleware rewrites the downstream render target.Previously, Pages prod wrote the middleware rewrite into
resolvedUrl, derivedresolvedPathnamefrom that rewritten URL, and then fed that rewritten pathname intomatchHeaders()andmatchRedirect(). That caused config headers/redirects to run against the middleware target instead of the pre-middleware request path.This change updates both Pages production paths to preserve the original normalized
pathnamefor config header/redirect matching while continuing to useresolvedUrl/resolvedPathnamefor downstream rewrites, API routing, and page rendering.Changes
pathnamefor:matchHeaders()matchRedirect()headers()still applying after a middleware rewriteredirects()still winning before a middleware rewrite targetTesting
pnpm test tests/pages-router.test.ts tests/deploy.test.ts tests/entry-templates.test.tspnpm run fmtpnpm run typecheck🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.