staminna
staminna

Reputation: 468

API is using CORS, how can I use axios in vue?

I need to do a GET request from a CORS enabled corona virus API with axios and Vue, and I have no control over their server. My Vue app was created with vue-cli.

Actually I do two requests from different API's, one works without CORS the other with the exact same code, but on a second component complains just because the server enforces CORS

Access to XMLHttpRequest at 'http://corona-api.com/countries' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What can I do?

Upvotes: 0

Views: 413

Answers (1)

baku
baku

Reputation: 775

the issue is that http is being redireced to https, you get a redirect header, which is absent of wildcard CORS policy.

as you can see, https://codesandbox.io/s/javascript-es6-axios-app-y80n5

this works fine for axios request to 'https://corona-api.com/countries'

Upvotes: 1

Related Questions