mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1087] [MERGED] refactor(server): dedupe HTTP error response builders #1085
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#1085
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/1087
Author: @james-elicx
Created: 5/5/2026
Status: ✅ Merged
Merged: 5/5/2026
Merged by: @james-elicx
Base:
main← Head:refactor/dedupe-http-error-responses📝 Commits (2)
3b50586refactor(server): dedupe HTTP error response builders241a869ci: retrigger workflows📊 Changes
16 files changed (+140 additions, -54 deletions)
View changed files
📝
packages/vinext/src/server/app-middleware.ts(+2 -1)📝
packages/vinext/src/server/app-page-method.ts(+2 -5)📝
packages/vinext/src/server/app-page-request.ts(+3 -2)📝
packages/vinext/src/server/app-prerender-endpoints.ts(+3 -2)📝
packages/vinext/src/server/app-router-entry.ts(+4 -3)📝
packages/vinext/src/server/app-rsc-handler.ts(+4 -3)📝
packages/vinext/src/server/app-rsc-request-normalization.ts(+3 -2)📝
packages/vinext/src/server/app-server-action-execution.ts(+5 -10)📝
packages/vinext/src/server/app-ssr-entry.ts(+3 -2)➕
packages/vinext/src/server/http-error-responses.ts(+90 -0)📝
packages/vinext/src/server/image-optimization.ts(+3 -1)📝
packages/vinext/src/server/metadata-route-response.ts(+6 -5)📝
packages/vinext/src/server/middleware-runtime.ts(+3 -2)📝
packages/vinext/src/server/pages-api-route.ts(+2 -1)📝
packages/vinext/src/server/prod-server.ts(+2 -4)📝
packages/vinext/src/server/request-pipeline.ts(+5 -11)📄 Description
Summary
Follow-up to #1058 / #1071 / #1078. Extracts a fresh batch of
new Response(...)HTTP error builders into a shared module,packages/vinext/src/server/http-error-responses.ts. Now home to:badRequestResponse(init?)— 400 "Bad Request"forbiddenResponse()— 403 "Forbidden" (moved fromrequest-pipeline.ts)notFoundResponse(init?)— 404 "Not Found"methodNotAllowedResponse(allowedMethods, init?)— 405 "Method Not Allowed" withAllowheaderpayloadTooLargeResponse()— 413 "Payload Too Large" (moved fromapp-server-action-execution.ts)internalServerErrorResponse(message?, init?)— 500 "Internal Server Error"Each helper accepts an optional
headersinit so callers (e.g.app-rsc-handler,app-page-method,prod-server) can merge middleware response headers without re-implementing thenew Response(...)boilerplate.Standardized status codes / sites touched
app-page-request.ts(×2) —validateAppPageDynamicParamsapp-prerender-endpoints.ts(×2) — disabled prerender endpointsapp-rsc-handler.ts— plain 404 fallback (with merged middleware headers)app-rsc-request-normalization.ts— basePath missapp-router-entry.ts(×2) — protocol-relative guard, null resultapp-ssr-entry.ts(×2) — protocol-relative guard, null resultmetadata-route-response.ts(×5) — sitemap/image/dynamic 404sprod-server.ts— Node static-served 404 (with merged static headers)request-pipeline.ts(×2) —guardProtocolRelativeUrl,normalizeTrailingSlashapp-router-entry.ts,app-rsc-request-normalization.ts,image-optimization.ts,middleware-runtime.tsAllow: GET, HEAD)app-page-method.tsapp-middleware.ts,pages-api-route.tsmiddleware-runtime.ts(dev-mode dynamic message viainternalServerErrorResponse(message))app-server-action-execution.ts(×2; prod = canonical, dev = "Server action failed: ..." viainternalServerErrorResponse(message))payloadTooLargeResponseis now the shared symbol)Body string changes (intentional, called out)
Five sites that previously returned the body
"404 Not Found"(the protocol-relative open-redirect guards inrequest-pipeline.ts×2,app-router-entry.ts,app-ssr-entry.ts, plus the trailing-slash defense-in-depth check) now return the canonical"Not Found"body. Status code (404) and absence ofContent-Typeare unchanged. The sibling generated-worker template strings indeploy.tskeep the old body to avoid touching codegen output.Sites left inline (intentional)
deploy.ts,entries/pages-server-entry.ts,server/dev-origin-check.ts.pages-api-route.ts:47andprod-server.ts:1593keep"404 - API route not found"(asserted intests/pages-api-route.test.ts:148);pages-api-route.ts:53keeps"API route does not export a default function".app-page-dispatch.ts:303("Page has no default export");pages-page-data.ts:139("404");image-optimization.ts(×4:"Image not found","The requested resource is not an allowed image type");app-prerender-endpoints.ts(×2:"missing pattern");request-pipeline.ts(image-URL validation custom bodies).app-route-handler-dispatch.ts(new Response(null, { status: 400 / 405 })),app-route-handler-execution.ts(status: 500with null body) — different shape from text-body helpers.config-matchers.ts(proxy gateway responses).Test plan
pnpm vp test run tests/app-router.test.ts— 308 passedpnpm vp test run tests/pages-router.test.ts— 200 tests pass (pre-existing afterAll cleanup hook timeout, unrelated to this change; verified by stashing the diff and reproducing on main)pnpm vp test run tests/app-rsc-handler.test.ts tests/app-prerender-endpoints.test.ts tests/app-page-request.test.ts tests/pages-api-route.test.ts tests/api-handler.test.ts tests/app-page-dispatch.test.ts tests/metadata-route-response.test.ts tests/app-page-route-wiring.test.ts tests/app-page-execution.test.ts tests/app-route-handler-policy.test.ts tests/image-optimization-parity.test.ts tests/image-config.test.ts tests/app-post-middleware-context.test.ts— 230 passedpnpm fmt --writepnpm knip— clean🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.