3

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?

2
  • Are you running applications in same network? Or are they in seperate docker containers? Commented Oct 2, 2019 at 7:02
  • refer this stackoverflow.com/a/58179439/11982418 Commented Oct 2, 2019 at 7:18

4 Answers 4

1

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

 "proxy": "http://localhost:8000/"
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

I just change

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

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.