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 api.

here is my code for redux-observable Epic

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

and here is console error

XMLHttpRequest cannot load 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
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