Skip to content

Align Pages Router worker entry with prod-server request handling#171

Merged
southpolesteve merged 4 commits intomainfrom
fix/pages-router-worker-request-handling
Feb 27, 2026
Merged

Align Pages Router worker entry with prod-server request handling#171
southpolesteve merged 4 commits intomainfrom
fix/pages-router-worker-request-handling

Conversation

@southpolesteve
Copy link
Copy Markdown
Collaborator

Summary

The generated Cloudflare Worker entry for Pages Router apps (generatePagesRouterWorkerEntry()) was missing several request handling steps that the Node.js production server (prod-server.ts) already handled. This brings the two implementations in sync.

  • Import and call runMiddleware and apply vinextConfig rules (redirects, rewrites, headers) in the generated worker entry
  • Handle basePath stripping, trailing slash normalization, and request context construction in the same order as prod-server
  • Merge middleware/config headers into responses with correct precedence (response headers override middleware headers)
  • Guard renderPage with a typeof check for robustness
  • Export vinext/config/config-matchers from the package so the worker entry can import the shared matching utilities
  • Update both Pages Router examples (pages-router-cloudflare, realworld-api-rest) to match

Test plan

  • 133 deploy tests pass (17 new, covering middleware execution, config application, ordering, header precedence, basePath handling)
  • Typecheck clean (tsgo --noEmit)
  • Lint clean (oxlint --deny-warnings)

Fork PRs don't have access to repository secrets (CLOUDFLARE_API_TOKEN,
CLOUDFLARE_ACCOUNT_ID), so deploy/smoke-test/comment steps always fail.
Add a fork detection condition to skip these steps gracefully. The build
steps still run, so example builds are still validated for fork PRs.
The generated Cloudflare Worker entry for Pages Router apps was missing
several request handling steps that the Node.js production server
(prod-server.ts) already handled. This brings the two in sync:

- Run middleware (runMiddleware) before routing
- Apply next.config.js redirects, rewrites (before/after/fallback), and headers
- Handle basePath stripping and trailing slash normalization
- Merge middleware response headers with correct precedence
- Guard renderPage with typeof check

Also updates the two Pages Router examples (pages-router-cloudflare,
realworld-api-rest) and exports vinext/config/config-matchers so the
worker entry can import the shared matching utilities.
Incorporate upstream changes: backslash normalization for open redirect
checks, allowedWidths for image optimization, and other main branch
updates.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 27, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@171

commit: 63db9cd

@github-actions
Copy link
Copy Markdown

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

@southpolesteve southpolesteve merged commit 75703d3 into main Feb 27, 2026
23 checks passed
@southpolesteve southpolesteve deleted the fix/pages-router-worker-request-handling branch February 27, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant