React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)

前端 未结 6 1415
忘了有多久
忘了有多久 2021-01-17 08:02

I have a React frontend that uses jwt to authenticate with the Django backend. The backend works and is connecting just fine using django views, but when I try to proxy a r

6条回答
  •  一生所求
    2021-01-17 08:10

    I'm running into the same problem as well. Most search results mention adding "secure": false or "ignorePath": true to your proxy config. Something like this:

    "proxy": {
        "/api/*":  {
          "target": "http://localhost:8000",
          "secure": false
        }
      },
    

    May be worth a try but unfortunately none of this worked for me. Although each address (http://localhost:3000 and http://localhost:8000) work completely fine in the browser, maybe since the container is actually proxying it needs to use a Docker address?

    EDIT--

    Alright I think I figured it out. I believe it did have to do with the container to container communication. Looking in your docker-compose, your api server is called django. Change your package.json file to this:

    "proxy": {
        "/api/*":  {
          "target": "http://django:8000",
          "secure": false
        }
      }
    

提交回复
热议问题