{"id":736,"hash":"fda570f6cc91da3ce4851ad4b5e1e3d58f7f757f05cf591b16f19663d3b9853d","pattern":"React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)","full_message":"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 request from React, it gives me a Connection Refused error.\n\n  Proxy error: Could not proxy request /api/auth/token/obtain/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED).\n\nConnecting to http://localhost:8000/api/auth/token/obtain/ works normally.  And sending a POST request with Axios also works normally and returns the token json.  But when I proxy it with node, it doesn't work.\n\nIn my package.json I have:\n\n  \"proxy\": {\n    \"/api/*\":  {\n      \"target\": \"http://localhost:8000\"\n    }\n  },\n\nEdit:  Public repo.  You can run easily if you have docker installed. (uses 1 image and 2 containers).  After cloning just run docker-compose build, then docker-compose up.\n\nEdit2: Headers of request:\n\n*General*\nRequest URL: http://localhost:3000/api/auth/token/obtain/\nRequest Method: POST\nStatus Code: 500 Internal Server Error\nRemote Address: [::1]:3000\nReferrer Policy: no-referrer-when-downgrade\n\n*Response Headers*\nHTTP/1.1 500 Internal Server Error\nX-Powered-By: Express\nDate: Mon, 30 Apr 2018 21:23:17 GMT\nConnection: keep-alive\nTransfer-Encoding: chunked\n\n*Request Headers\nPOST /api/auth/token/obtain/ HTTP/1.1\nHost: localhost:3000\nConnection: keep-alive\nContent-Length: 45\nPragma: no-cache\nCache-Control: no-cache\nOrigin: http://localhost:3000\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36\nContent-Type: application/json\nAccept: */*\nReferer: http://localhost:3000/login\nAccept-Encoding: gzip, deflate, br\nAccept-Language: en-US,en;q=0.9,fr;q=0.8,ja;q=0.7","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"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. \n\nSo 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 \n\n\"proxy\": {\n    \"/api\":  {\n        \"target\": \"http://django:8000\"\n    }\n},\n\nAnd 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.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/50107816/react-proxy-error-could-not-proxy-request-api-from-localhost3000-to-http-l","votes":49,"created_at":"2026-04-19T04:51:33.566014+00:00","updated_at":"2026-04-19T04:51:33.566014+00:00"}