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

Cross-Origin Request Blocked #46

Closed
ciarlystreet opened this issue May 21, 2019 · 3 comments
Closed

Cross-Origin Request Blocked #46

ciarlystreet opened this issue May 21, 2019 · 3 comments

Comments

@ciarlystreet
Copy link

ciarlystreet commented May 21, 2019

Hi,
I keep getting this error when trying to access your APIs

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.exchangeratesapi.io/latest?base=EUR. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)

My script:

async asyncData({ $axios, error, params }) {
    try {
       const { data } = await $axios.get(
        'https://api.exchangeratesapi.io/latest',
        {
          params: {
            base: 'EUR'
          }
        }
      )
      const rates = data.rates
      })
      return {
        rates
      }
    } catch (e) {
      error({
        statusCode: 503,
        message: 'API connection error'
      })
    }
  }
@madisvain
Copy link
Collaborator

@ciarlystreet I tested it with a CORS testing site: https://www.test-cors.org/

It seems everything is correct and it loads just fine. Can you please take a look at your implementation.
Screenshot 2019-05-25 12 02 36

@technoknol
Copy link

@madisvain I'm using Axios in React, it's calling OPTIONS requests first. And there's an error. Any suggestions for this ?

@CaddyDz
Copy link

CaddyDz commented Feb 7, 2020

I got around the issue with a proxy, you should still fix it tho

axios
	.get(
		"https://cors-anywhere.herokuapp.com/https://api.exchangeratesapi.io/latest?symbols=USD"
	)
	.then(response => {
		this.exchangeRate = response.data.rates.USD;
	});

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

No branches or pull requests

4 participants