Skip to content

Unable to access assets due to CORS #2872

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

Closed
filoxo opened this issue Oct 24, 2016 · 4 comments · Fixed by #3009
Closed

Unable to access assets due to CORS #2872

filoxo opened this issue Oct 24, 2016 · 4 comments · Fixed by #3009
Labels
P5 The team acknowledges the request but does not plan to address it, it remains open for discussion

Comments

@filoxo
Copy link
Contributor

filoxo commented Oct 24, 2016

OS?

Mac OSX El Capitan

Versions.

angular-cli: 1.0.0-beta.18
node: 6.7.0
os: darwin x64

Repro steps.

  • Upgraded from [email protected] to 1.0.0-beta.18 (as well as Typescript from 2.0.2 to ~2.0.3).
  • Changed assets key in angular-cli.json to array of strings.

The log given by the failure.

XMLHttpRequest cannot load http://localhost:4200/assets/i18n/en.json. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:8080' is therefore not allowed access.

Mention any other details that might be useful.

My use case: I am not using the generated index.html, but instead use Java/Spring. I run both the backend and the CLI concurrently, the CLI dev-server acting as a local CDN for development. Therefore the page is served from the backend on :8080 and the Angular app from :4200.

Related to #803 though for different reasons since the CLI now uses Webpack/webpack-dev-server. Because the CLI doesn't expose any config for webpack, users can't enable CORS themselves. This seemed to work previously without any issue. Attempts to downgrad to beta.16 (npm i -g [email protected]) seem to either install beta.18 again or fail with error:

Cannot read property 'AssetUrl' of undefined
TypeError: Cannot read property 'AssetUrl' of undefined
@filoxo
Copy link
Contributor Author

filoxo commented Oct 31, 2016

I was able to successfully downgrade my project CLI 1.0.0-beta.16; globally installing this version seems to succeed but I get error Cannot find module '@angular-cli/ast-tools when attempting to use outside of a CLI project. My project now works again, but won't be able to upgrade to the latest version of the CLI until a solution allows me to access assets from another origin.

@filipesilva
Copy link
Contributor

Would you be willing to make a PR that enables CORS for ng serve? I'm happy to review it.

@filipesilva filipesilva added type: enhancement P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels Nov 3, 2016
filoxo pushed a commit to filoxo/angular-cli that referenced this issue Nov 3, 2016
@cacogr
Copy link

cacogr commented Nov 11, 2016

As a workaround I'm using a browser extension that sets the header Access-Control-Allow-Origin: * using a filter for requests matching the pattern *://localhost*/*.

https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P5 The team acknowledges the request but does not plan to address it, it remains open for discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants