1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

docker環境化でReactのproxyが通らない時の対処法

Last updated at Posted at 2022-09-01

Docker環境化でpackage.jsonの中に"proxy": "http:localhost:8000/api"と書いてGETリクエストを送っても、Proxy error: Could not proxy requestとエラーが出て怒られました。

期待した動き

http://localhost:3000/postsに対してGETリクエストを送った際に、proxyを通してhttp://localhost:8000/api/postに飛んでほしかった

実際の動き

めっちゃエラーでてくる

原因

docker環境化でlocalhostを指定するとどこにいけばよいかわからなくなるらしい

対応策

package.jsonでproxyを指定する時にdockerコンテナのサービス名を指定してあげるとうまく行く

"proxy": "http://<dockerのサービス名>:8000/api"

proxyを変えた後はdocker-compose restartで再起動する

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?