-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Access-Control-Allow-Origin header missing in dev server for assets #29549
Comments
Can you explain why you need this header? If you're accessing resources from a different host, this behavior is expected. For more details, see: #29471. |
Longer answerIn our case: We have a multi-frontend-system. The "main"-system runs somewhere in cloud (for example under "example.com") and loads its configured subsystems from various different domains ("exampleA.com", "exampleB.com", and so on). For developing-purposes it is necessary that we can use the "manifest.json" from our local environment. We can say at domain "example.com" that one manifest can be found at localhost. Then the system tries to load the "localhost:4200/assets/manifest.json" file while the webpage is running under "example.com". I will have a look at #29471 tomorrow. Maybe it solves our problems. |
Patch versions should never introduce breaking changes. Our workaround is to set the header manually. "serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"headers": {
"Access-Control-Allow-Origin": "*"
}, |
I tried to set "serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"allowedHosts": ["example.com"]
}, but it won't work. I got a warning "The "allowedHosts" option will not be used because it is not supported by the "@angular-devkit/build-angular:application" builder.", is it already released? The workaround of @vkennke works well. |
The warning is no longer relevant and should be removed, setting the @vkennke, you're right that patch updates should avoid breaking changes. However, in this case, it was necessary to address a security vulnerability in Vite. |
Vite's `allowedHosts` option does not enable CORS; instead, it allows the dev server to respond to requests with a matching hostname (e.g., http://example.com/main.js). It only verifies that the request’s hostname is on the allowed list. However, this does not consider the `origin` in the case of a CORS request. This commit updates Vite's configuration to enable CORS. Closes angular#29549
Vite's `allowedHosts` option does not enable CORS; instead, it allows the dev server to respond to requests with a matching hostname (e.g., http://example.com/main.js). It only verifies that the request’s hostname is on the allowed list. However, this does not consider the `origin` in the case of a CORS request. This commit updates Vite's configuration to enable CORS. Closes angular#29549
Vite's `allowedHosts` option does not enable CORS; instead, it allows the dev server to respond to requests with a matching hostname (e.g., http://example.com/main.js). It only verifies that the request’s hostname is on the allowed list. However, this does not consider the `origin` in the case of a CORS request. This commit updates Vite's configuration to enable CORS. Closes angular#29549
Vite's `allowedHosts` option does not enable CORS; instead, it allows the dev server to respond to requests with a matching hostname (e.g., http://example.com/main.js). It only verifies that the request’s hostname is on the allowed list. However, this does not consider the `origin` in the case of a CORS request. This commit updates Vite's configuration to enable CORS. Closes #29549 (cherry picked from commit be15b88)
Confirmed. In 19.1.7 is all fine again. Thanks @alan-agius4. 👍 |
Command
serve
Is this a regression?
The previous version in which this bug was not present was
@angular-devkit/build-angular 19.1.4
Description
Starting with Angular 19.1.5, when running the development server using
ng serve
, theAccess-Control-Allow-Origin
header is no longer included in responses when accessing assets. In version 19.1.4, this header was still being sent with the value '*'.This affects cross-origin requests to static assets served by the development server.
Minimal Reproduction
Repository for minimal reproduction:
[Link to Git Repository]
Steps to reproduce:
git clone https://github.com/vkennke/angular-cors.git cd angular-cors npm install
Expected behavior:
Response headers include Access-Control-Allow-Origin: *
Actual behavior:
Access-Control-Allow-Origin header is missing from response
To verify this is a regression:
Exception or Error
Your Environment
Anything else relevant?
No response
The text was updated successfully, but these errors were encountered: