gnujoow gnujoow -4 years ago 148
Ajax Question

No 'Access-Control-Allow-Origin' over rxjs

I've been building up simple react app which shows following crytowat.ch api.
https://api.cryptowat.ch/markets

here is my code for redux-observable Epic

const cryptowatchEpic = action$ =>
action$.ofType(FETCH_PRICE).mergeMap(action =>
ajax({
url: `${baseUrl}${action.payload}/btcusd/price`,
crossDomain: true,
method: 'GET',
headers: {
'Access-Control-Request-Origin': 'https://api.cryptowat.ch/'
},
withCredentials: true
}).map(response => fetchPriceFilled(response))
);


and here is console error


XMLHttpRequest cannot load https://api.cryptowat.ch/markets/kraken/btcusd/price. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 405.


I think passed
Access-Control-Request-Origin
in headers but i occurs error. is there something i missed?

thanks in advance

Answer Source

You've got it backwards.

The server is the one responsible for sending the 'Access-Control-Request-Origin' header, not the client.

So, in other words, you need server-side access to add those headers there. More info at "No 'Access-Control-Allow-Origin' header is present on the requested resource".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download