没有 'Access-Control-Allow-Origin' 超过 rxjs

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

我一直在构建简单的 React 应用程序,它显示了以下 crytowat.ch api。 https://api.cryptowat.ch/markets

这是我的 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))
  );

这是控制台错误

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.

我认为在 headers 中通过了 Access-Control-Request-Origin,但我发生了错误。我错过了什么吗?

提前致谢

你搞反了。

服务器负责发送 'Access-Control-Request-Origin' header,而不是客户端。

因此,换句话说,您需要 server-side 访问权限才能在其中添加那些 header。更多信息,请访问 "No 'Access-Control-Allow-Origin' header is present on the requested resource"