Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): allow server.headers to override server.cors #4898

Merged
merged 4 commits into from
Mar 28, 2025

Conversation

chenjiahan
Copy link
Member

Summary

Allow server.headers to override server.cors. This ensures that fields explicitly defined in server.headers always work as expected.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 46e351e
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/67e5ebb2b1595000086136d2
😎 Deploy Preview https://deploy-preview-4898--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 80 (🟢 up 21 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.headers and server.cors consistently.
// server.headers` can override `server.cors`

@chenjiahan chenjiahan merged commit 424b946 into main Mar 28, 2025
11 checks passed
@chenjiahan chenjiahan deleted the header_override_0327 branch March 28, 2025 02:14
@chenjiahan chenjiahan mentioned this pull request Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant