fix(server): allow server.headers to override server.cors#4898
Merged
chenjiahan merged 4 commits intomainfrom Mar 28, 2025
Merged
fix(server): allow server.headers to override server.cors#4898chenjiahan merged 4 commits intomainfrom
server.headers to override server.cors#4898chenjiahan merged 4 commits intomainfrom
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates the server configuration so that user-defined server.headers take precedence over server.cors.
- Moved the header-setting middleware to execute after the CORS middleware in both the production and development server setups.
- Updated tests to confirm that server.headers override server.cors, and adjusted proxy tests accordingly.
Reviewed Changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/core/src/server/prodServer.ts | Reordered header middleware to run after CORS middleware. |
| packages/core/src/server/devMiddlewares.ts | Updated middleware order to ensure header override behavior. |
| e2e/cases/server/proxy/index.test.ts | Changed test config for proxy server from headers to cors. |
| e2e/cases/server/cors/index.test.ts | Added tests to validate that headers override CORS in both dev and preview servers. |
Files not reviewed (2)
- website/docs/en/config/server/headers.mdx: Language not supported
- website/docs/zh/config/server/headers.mdx: Language not supported
Comments suppressed due to low confidence (1)
packages/core/src/server/devMiddlewares.ts:104
- [nitpick] Inconsistent backtick usage in the comment; consider formatting both
server.headersandserver.corsconsistently.
// server.headers` can override `server.cors`
chenjiahan
commented
Mar 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Allow
server.headersto overrideserver.cors. This ensures that fields explicitly defined inserver.headersalways work as expected.Checklist