私は、React-App内で外部APIからデータを取得しようとします。私はCORS-事が唯一のクライアント側の要求に必要とされて知っているようにサーバ - のために、限りReactJSベースのノードアプリケーション内の外部APIからサーバー側のデータを取得する方法は?
// @flow
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
const URL = 'http://api.example.com/my/api/request' // obfuscated
class App extends Component {
componentDidMount() {
fetch(URL).then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
})
}
render() {
return (
<div className="App">
<small>You are running this application in <b>{process.env.NODE_ENV}</b> mode.</small>
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React!</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
);
}
}
export default App;
ない:これは私のコードである
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://api.example.com ' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
:しかし、それは常に私に次のエラーを与えますサイドリクエスト。
誰が私を助けることができますか?