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.

Leave a Comment