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

How can I enable CORS (Cross-Origin Resource Sharing) ? #68

Closed
garaving opened this issue Jan 24, 2018 · 17 comments
Closed

How can I enable CORS (Cross-Origin Resource Sharing) ? #68

garaving opened this issue Jan 24, 2018 · 17 comments
Assignees
Labels

Comments

@garaving
Copy link

Failed to load http://xxxxxx.com//assets/i18n/it.json: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:5500' is therefore not allowed access.

@garaving garaving changed the title How can I enable cors? How can I enable CORS (Cross-Origin Resource Sharing) ? Jan 24, 2018
@ritwickdey
Copy link
Owner

Same as #64

@ritwickdey
Copy link
Owner

This features is already added in v3.1.0. (Sorry, I forget to close it)

@amirblum
Copy link

It seems like CORS still isn't enabled on the local server. I tested using test-cars.org and returns an error when trying to GET one of the files from the server. Any additional steps I'm missing? Anything that needs to be enabled in the settings?

@Beta6484
Copy link

I still can't access .json files from external domains. Am I forgetting to set something up?

@JonathanWilbur
Copy link

acao

@JammiM
Copy link

JammiM commented Jan 16, 2019

screen shot 2019-01-16 at 21 56 04
I have also encountered a CORS issue when trying to request a API, are you sure that you have CORS enabled ?

I'm using Safari version 11.1.2

the endpoint is
https://www.cryptocompare.com/api/data/coinlist

@SuperRoach
Copy link

Using 5.4.0, I'm getting the same problem when trying to call https://api.flickr.com/services . This is with Firefox.

@veuncent
Copy link

veuncent commented May 9, 2019

Same issue here in Chrome, Firefox and Edge on Windows 10.
Is there anything we need to configure before this would work? Thanks!

Edit: I seem to have fixed my issue by simply loosening the CORS settings on my target resource. Now I don't get any errors anymore regarding a missing 'Access-Control-Allow-Origin' header.

@larryhu
Copy link

larryhu commented May 31, 2019

Temporary suggestion -> #249 (comment)

@flyingduck92
Copy link

Hey I have the same issue when using d3.js. How to fix this issue?

d3.html('http://enable-cors.org')
  .get((err, data) => {
    console.log(data)
  })

image

@GoudronViande24
Copy link

Still hasn't been fixed.

@RafaPatino01
Copy link

Same problem

XHRGEThttp://example.com/movies.json
[HTTP/1.1 404 Not Found 81ms]

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com/movies.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404.

Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.
GEThttp://127.0.0.1:5500/favicon.ico

@shadynasrat
Copy link

Still some times its not working... please fix this

@sgalcheung
Copy link

sgalcheung commented May 20, 2022

same problem, I use the latest Live Server v5.7.5

you can try live-server --cors using npm live server

@andreas-stricker
Copy link

same problem here with Live Server v5.7.9

@vacing
Copy link

vacing commented Dec 8, 2022

@asitanc
Copy link

asitanc commented Dec 22, 2022

Access-Control-Allow-Origin can have three possible directives (*, origin, or null) to tell the browser from which origin can one access certain resources.

The issue is with the response from the backend which is/was missing appropriate header. Thats why the issue is occurring "sometimes"; with some URLs or with other tools as well. And it should be unrelated to liveserver in vscode.

One cannot fetch a resource that they are not allowed to fetch.

So, your backend should return response with header Access-Control-Allow-Origin as wildcard (*) or specify the origin. If you specify the origin, the origin must match with your server (if you make request from example.com; the origin must be example.com).

You can check the headers using cURL with --head parameter for further troubleshooting of the backend responses.

Also, some sources are available here:

There is also very very nice explanation of how the header works here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests