How can I explicitly use localhost as the server while allowing the React application to be proxied to the Go backend?
P粉716228245
P粉716228245 2024-04-03 08:20:24
0
1
393

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粉716228245
P粉716228245

reply all(1)
P粉015402013

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"
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!