3
votes

I have a React frontend that uses jwt to authenticate with the laravel backend. The backend works and is connecting just fine using laravel views, but when I try to proxy a request from React, it gives me a Connection Refused error.

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

Connecting to http://localhost:8000/api/register 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.

in my package.json code is

"proxy": "http://localhost:8000",

Please anyone help me. how to fixed it?

3
Are you running applications in same network? Or are they in seperate docker containers? - onuriltan

3 Answers

0
votes

I think you should add "/" after the port number in package.json file

 "proxy": "http://localhost:8000/"
0
votes

Please check these points and solve your problem:

  1. Please check your ip of backend server.(https://127.0.0.1:3000 or http://127.0.0.1:3000)
  2. Please check your backend server is running or stop if stopped then start ypur server.
  3. Please check protocol http or https used in your backend server.(https or http)

I hope with the help of these points you can solved your problem which is facing by you.

0
votes

You need to run both of the local host (3000 and 8000) in different terminal. For example, run the backend server in os(windows's) command prompt cmd and frontend server in vscode terminal.