Proxy error: Could not proxy request ... from localhost:3000 to http://localhost:5000/ - node.js

How to fix the error below?
Proxy error: Could not proxy request /api/auth/register from localhost:3000 to http://localhost:5000/.
1 See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).

Run backend and this error will be removed automatically.

You must have set "proxy": "http://localhost:5000/" in your package.json in your client side.
What this does is that it prefixes every request with the proxy.
So this problem will arise if your backend server is listening at port other than 5000(since your every request will be directed at http://localhost:5000/<api>)
SOLUTION:
either change the proxy to what your backend server is listening at
or
change the backend server's listening port to what the proxy is set at.

Related

Ngrok invalid host header

I am using ngrok to expose my react app. Due to an "invalid host header", I have re-written the host header using ngrok http 3000 -host-header="localhost:3000", which works fine.
The problem that I am encountering is that when I added in my backend node.js server, I added multiple tunnels to my ngrok.yml file :
tunnels:
first:
addr: 3000
proto: http
second:
addr: 5000
proto: http
Now, to expose react & node.js, I am using
ngrok start --all
But now I am back to the issue where I am getting the invalid host header on my front end. How do I rewrite my host header for my front end with the "ngrok start --all"?
I have managed to solve this issue for others who do encounter a similar situation.
In the ngrok.yml file, include host_header: "localhost:3000"

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

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?
I think you should add "/" after the port number in package.json file
"proxy": "http://localhost:8000/"
Please check these points and solve your problem:
Please check your ip of backend server.(https://127.0.0.1:3000 or http://127.0.0.1:3000)
Please check your backend server is running or stop if stopped then start ypur server.
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.
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.

Application working on http but not on https

Background: I have two backend instances running haproxy, apache, nodejs on ports 4000 and 8007 for haproxy, 80 for httpd, 3000 3007 3012 running node. I have a staging site which is running on this instance. I have signed certificate installed at ELB level and ELB listening on https 443 port to backend http 80 port.
Issue: When I tried to login to the stating url with http then the backend is working fine on port 80 and 3000, network flow logs also returning status code as Ok for request to http://stating _url:3000. But when I tried to access site on https then I am getting status as "blocked:mixed-content" for https://stating _url:3000 request. Please refer to below screenshots
Below is output for http which is working as expected
Below is the output for https which is not working as expected
I tried different protocols for listeners at ELB level. I dont understand why ELB on port 80 sends request to port 80 on backend server and all works fine but same ELB on port 443 sends request to same port 80 on backend server but fails to establish connection with 3000.

ECONNRESET proxy error between dev server and API

When I run my development server, I get the following error.
Proxy error: Could not proxy request /graphql from localhost:3000 to http://localhost:3010.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
It is preventing me from proxying any requests from the development server to the API.
After debugging, I realized it was not a problem with the code because my colleague and I are working from the same repo and he does not have this error. Also, sometimes if I restart my terminal the error will go away before it comes back again.
Would greatly appreciate guidance on what is the root of this issue and how I can resolve it.
What I discovered, and what seems to have solved the problem, is that I was running too many different servers on ports that were too close together. My servers were running on port 3000, 3010, and 3009. I noticed that whenever the server at 3009 was running, I would get the above error. When I changed the port for that server from 3009 to 9999, all proxy errors ceased.

Accessing Node Proxy Server from a locally hosted file

I'm trying to access a node proxy server running on my local machine from somewhere else(specified later). I've tried setting proxy listening domain to 0.0.0.0 with with port 8888. The file that will send request to the proxy server is hosted using a simpleHttpServer at 127.0.0.1 with port 4444 on another computer. In this file, I'm sending the request to http://my_local_ip:8888 (I'm assuming this is where the Node Proxy lives on my computer). However, I'm get connection timeout for some reason. Does anyone see problems with this approach?

Resources