Skip to content

fix(dev): apply server headers to 404 responses (fix #22543)#22544

Open
sjh9714 wants to merge 1 commit into
vitejs:mainfrom
sjh9714:fix-server-headers-post-404
Open

fix(dev): apply server headers to 404 responses (fix #22543)#22544
sjh9714 wants to merge 1 commit into
vitejs:mainfrom
sjh9714:fix-server-headers-post-404

Conversation

@sjh9714
Copy link
Copy Markdown

@sjh9714 sjh9714 commented May 28, 2026

Summary

Fixes #22543.

server.headers was applied by built-in asset, HTML, and transform response paths, but not by the dev server fallthrough 404 path. This adds a lightweight headers middleware after CORS and host validation so POST/API-style 404 responses include configured server headers too.

Changes

  • Apply configured dev server.headers before user and built-in response middlewares run.
  • Add a unit regression test for a POST request that falls through to Vite's 404 handler.

Testing

  • pnpm install --frozen-lockfile
  • pnpm --filter=./packages/vite run build-bundle
  • pnpm test-unit packages/vite/src/node/__tests__/dev.spec.ts
  • pnpm exec eslint --cache --concurrency auto packages/vite/src/node/server/index.ts packages/vite/src/node/__tests__/dev.spec.ts
  • pnpm --filter=./packages/vite run build-types-roll
  • pnpm --filter=./packages/vite run typecheck
  • git diff --check
  • pnpm exec oxfmt --check packages/vite/src/node/server/index.ts packages/vite/src/node/__tests__/dev.spec.ts

Note: I used Codex while preparing this change, reviewed the final diff, and ran the listed checks locally.

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.

server.headers configuration not applied consistently.

1 participant