search

Home  >  Q&A  >  body text

How can I explicitly use localhost as the server while allowing the React application to be proxied to the Go backend?

I have a backend written in Go. Everything is working fine and the call from POSTMAN is being delivered, but suddenly I can't get the React app to call this server because I get the error:

Proxy error: Could not proxy request /login from localhost:3000 to http://localhost:8080 (ECONNREFUSED).

My Go server code:

log.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:8080"), api.router))

The package.json for the React application looks like this:

"proxy": "http://localhost:8080"

I know I can bind all interfaces in Go like this:

log.Fatal(http.ListenAndServe(fmt.Sprintf(":8080"), api.router))

But Mac OS asks me to allow this connection, but I can't do it because I'm not the administrator of the computer

I could do this via co-design, but I don't have any identity at the moment, so generating the private key and adding it to the keychain would also take some time

Is there any easy way to bypass this?

P粉716228245P粉716228245235 days ago466

reply all(1)I'll reply

  • P粉015402013

    P粉0154020132024-04-04 00:58:38

    Have you tried adding a slash at the end of the react agent line like this:

    "proxy": "http://localhost:8080/"

    The above was found here

    in questions similar to yours

    Also, you can try changing the proxy from localhost to 127.0.0.1:

    "proxy": "http://127.0.0.1:8080"

    reply
    0
  • Cancelreply