LoginSignup
1
2

More than 3 years have passed since last update.

node-redで「No 'Access-Control-Allow-Origin' header」が消えない(react)

Last updated at Posted at 2019-05-15

事象

reactで作成したwebアプリケーションから、node-redで作成したAPIにアクセスすると下記のエラーが出る。

Access to XMLHttpRequest at 'http://127.0.0.1:1880/api/v1/get/image' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

スクリーンショット 2019-05-15 18.29.34.png

対応1

Http responseのHeaderに"Access-Control-Allow-Origin": "*"を追加
スクリーンショット 2019-05-15 18.23.09.png

エラーは解消されませんでした。

対応2 (解決)

node-redの「setting.js」の「httpNodeCors」をコメントアウト解除
setting.jsのパス: /Users/{ユーザー名}/.node-red/settings.js
*macのPCでnpmでグローバルにインストールした場合

スクリーンショット 2019-05-15 17.28.21.png

解決しました!

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2