React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)
So the issue was since both the Node dev environment and the Django dev environment were running in separate docker containers, so localhost
was referring to the node container, not the bridged network.
So the key was to use container links, which are automatically created when using docker-compose
, and use that as the hostname. So I changed it to
"proxy": {
"/api": {
"target": "http://django:8000"
}
},
And that worked, as long as you launch both containers with the same docker-compose
command, otherwise you have to manually specify external_links in your docker-compose.yml
file.
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
}
}
If your on a newer version CRA 2.0+ you'll need to do this via a manual proxy. https://facebook.github.io/create-react-app/docs/proxying-api-requests-in-development#configuring-the-proxy-manually