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

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.

Related

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

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.

Unable to reach localhost:3000/

I'm working on a react application and for testing some services I wrote a node server in my notebook. It seems that from the app and from the browser I cannot point to https://localhost:3000 due to ERR_SSL_PROTOCOL_ERROR.
I just tried doing some actions like reset all SSL certificates, trying different browser but the only result I found it's that I can reach my server from the browser but not via react.
Can someone help me?
Try http://localhost:3000
Just validated with one of my projects to make sure
The dev server doesn't support https
The localhost:3000 should be hit by: "http://localhost:3000"
If that is not working then the port number can be changed.
In REACT, the port number can be changed with:
"start": "set PORT=3006 && react-scripts start"
How are you running the app? Maybe with
set HTTPS=false&&npm start

ECONNREFUSED error when proxying from React to Flask running in docker-compose

I've been all over this so finally asking.
I basically have a flask API and a react front end running on my dev machine.
They are running via docker-compose on the same virtual network.
The flask api runs perfectly when I postman to it via the 5000 port and the react front end works perfectly in the browser on port 3000.
I edited the react package.json file and added "proxy": "http://localhost:5000",
Then when running the route I want from react over on localhost:3000/movies it tries to proxy on over to localhost:5000/movies but I get this error:
Proxy error: Could not proxy request /movies from localhost:3000 to http://localhost:5000.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED)
I've tried changing that line to various things including my docker image name. So proxy": "http://image-name:5000", and I've also tried the internal docker network name like proxy": "http://127.0.0.1:5000", and they all give the same kind of error.
Does anyone have any suggestions as to what I can try beyond that? Any advice would be greatly appreciated. Thank you.
Here it is for anyone in the future.
The container name needed to be used. So I updated my docker-compose.yml to have:
services:
flask-api:
container_name: flask-api
In my API (flask app) my config.py was like so:
SERVER_NAME = 'localhost:5000'
I changed it to:
SERVER_NAME = 'flask-api:5000'
The react package.json was updated to:
"proxy": "http://flask-api:5000",
Then on reload docker-compose build --up it worked.
The proxy from react forwards to the flask api. So in my case localhost:3000/movies proxies to locahost:5000/movies to get my api data.
I trust that helps someone in the future.

Node not working properly

any ideia why my node only runs in http? The node keeps running but if you put https in browser the node will not work properly, as it only works properly on http,
Configuring Nginx and SSL with Node.js for HTTPS
Please go through the below link and follow all steps
Link
Note: It is mandatory to have Domain Name forwarding request to your working Node IP Address

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.

Resources