fix(@angular/build): allow configuring Access-Control-Allow-Origin via headers option#32976
Open
alan-agius4 wants to merge 1 commit intoangular:mainfrom
Open
fix(@angular/build): allow configuring Access-Control-Allow-Origin via headers option#32976alan-agius4 wants to merge 1 commit intoangular:mainfrom
alan-agius4 wants to merge 1 commit intoangular:mainfrom
Conversation
…a headers option Removes the default Vite CORS origin: true configuration, allowing custom Access-Control-Allow-Origin header configurations to take effect when using the development server. BREAKING CHANGE: The development server (ng serve) no longer automatically mirrors the request origin in the Access-Control-Allow-Origin response header by default. If your application relies on cross-origin requests during local development, you must now explicitly configure the required CORS headers using the headers option in your angular.json configuration. Fixes angular#32923
There was a problem hiding this comment.
Code Review
This pull request modifies the Angular dev server's Vite configuration to remove the default Access-Control-Allow-Origin: true setting, meaning the Access-Control-Allow-Origin header will no longer be automatically mirrored. A new test case was added to verify that when the header is explicitly configured, it is correctly applied. The reviewer suggests adding another test to explicitly confirm that the Access-Control-Allow-Origin header is not set by default when no headers option is provided, to fully cover the breaking change in behavior.
packages/angular/build/src/builders/dev-server/tests/options/headers_spec.ts
Show resolved
Hide resolved
dgp1130
approved these changes
Apr 9, 2026
| expect(await response?.headers.get('x-custom')).toBe('foo'); | ||
| }); | ||
|
|
||
| it('should include configured Access-Control-Allow-Origin header', async () => { |
Collaborator
There was a problem hiding this comment.
Consider: Should we add a test that the CORS header is not returned by default?
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.
Removes the default Vite CORS origin: true configuration, allowing custom Access-Control-Allow-Origin header configurations to take effect when using the development server.
BREAKING CHANGE: The development server (ng serve) no longer automatically mirrors the request origin in the Access-Control-Allow-Origin response header by default. If your application relies on cross-origin requests during local development, you must now explicitly configure the required CORS headers using the headers option in your angular.json configuration.
Fixes #32923