聞きたいこと
axiosを使用してHerokuに存在しているAPIサーバーからJSONをGetしたいと思っているのですが、
以下のようなエラーが発生してしまいできません。。。
- エラー内容
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3001' is therefore not allowed access.
詳細な環境や試したことを下にまとめます。
環境
フロントエンド:React ライブラリーでaxiosを使用
バックエンド(APIサーバー):Ruby on Rails(Herokuに存在)
試したこと
- axios.getする際のconfigを変更
const api_url = "https://xxx.herokuapp.com/api/v1" const config = { headers: {'Access-Control-Allow-Origin': '*'} } export const readRepositories = () => async dispatch => { const response = await axios.get(api_url, config); dispatch({ type: READ_REPOSITORIES, response }); }

あなたの回答
tips
プレビュー