Connection Refused While Accessing API - javascript

I have a nginx server where I have an api deployed at localhost:5000
On the same server I have a Vuejs app which is deployed at localhost:3000 and then through nginx reverse proxy served from www.mysite.com.
the frontend uses axios to make calls to the api. But everytime it happens, I get a connection refused error to localhost:5000.
Why is this happening and how can I resolve it.
Note: If I serve localhost:5000 api also via a domain like api.mysite.com using nginx reverse proxy and call api from this domain then it works fine. But I don't want to do that and instead want to use localhost:5000 to call the api.

Please check the port is listed by using the following command if you use Linux
sudo netstat -tnlp | grep :5000
If there is process running, then fine. Try changing the localhost to 127.0.0.1:5000

Related

How to update React localhost (127.0.0.1:3000) to another domain (local.example.com)

I am setting up a Localhost domain so it can communicate with this third-party API and Auth servers.
For example, change 127.0.0.1 to local.example.com
local.example.com is the domain whitelisted with this third-party enterprise. I need to set this up so i can run API routes to it.
I was able to change 127.0.0.1 locally in C:\Windows\System32\drivers\etc\hosts file and now Node.js is running on it.
I added the webpack config devServer - host to local.example.com but the port is still there. I need to understand how to change this for react because right now it's porting to local.example.com:3000.
A little late to the party but it still might be useful.
Go to C:\Windows\System32\drivers\etc\hosts and add this line:
127.0.0.1 local.example.com
In the React project, add a .env file with:
HOST=local.example.com
PORT=3006
I think you're almost there :-) The devServer option has a port property. Set that to 8080 or 80. Restart your server. Then, open the browser and try leaving it off the URL
After digging around, I found some solutions. Essential, my goal was to set http://localhost:3000 to http://local.example.com.
1. Add local.example.com to your hosts file (windows)
2. Set up your react port to 80
This would remove the 3000 on local.example.com:3000 to local.example.com
On HTTPS request, set the port to 443
This would result to https://local.example.com

WebSocket client can't connect to cloud server through corporate proxy except for web browsers! (ETIMEDOUT)

I'm trying to connect a WebSocket client (corporate Node.JS server) to a Cloud server, but it times out (connect ETIMEDOUT error).
I'm not sure which needs configuration... Linux, Node.JS or the WebSocket Client?
I've already configured the proxy for Linux (export proxy/https_proxy), and for Node.JS (npm config set proxy/https_proxy) but the problem persists!
I'm using the ws library found in https://npmjs.com and implemented it without any sort of options except setting port.
Any advice?
EDIT: Works fine in the web browser, by the way.
node does not automatically use any form of configuration for making HTTP requests through proxies -- ie, node does not read the PROXY or HTTPS_PROXY environment variables. npm config set proxy only affects npm itself.
In other words, node programs always try to access servers directly. It appears your network requires HTTP requests to go through a proxy, and direct connections are being silently dropped.
If you want your program to make HTTP requests through proxies, you must do so manually. The http-proxy-agent module can help you do this.

Heroku app served as HTTP with node.js

I have deployed a web application in Heroku using node.js but within the application I need to make a request to an HTTP endpoint that returns a JSON file. While making the request, I get the a Mixed content error. I understand this happens because my application has been served through HTTPS but the request is HTTP. How could I tell heroku to serve my application as HTTP or what should I do to make it HTTP? Will this solve the problem?

Consume Rest API on same ip but different port

Let's suppose a backend application, which exposes some Rest API, running on a Jetty webserver at address 192.168.1.10:8889.
I would like to have a frontend application (html/javascript only, on a apache2 webserver) running at the same IP but on a different port (e.g. 8000), which should consume the API exposed by the backend application.
How can i get this architecture working without get into "No 'Access-Control-Allow-Origin'" error?
I think that you should install a nginx proxy.
configure it as a reverse proxy you can see documentation here :
https://www.nginx.com/resources/admin-guide/reverse-proxy/
You can search on google for more specific documentation on what you want to do.

Meteor not being able to connect to prerender.io server

I have set up a prerender server on my local machine.
It is on port 3033 and it seems to display a rendered version of my meteor site when I type this in
curl http://localhost:3033/http://localhost:3000/?_escaped_fragment_=
Knowing that my prerender site works, I'm trying to set it up so that if I go to
curl http://localhost:3000/?_escaped_fragment_=
it should give me my Meteor site.
I'm using this package (https://github.com/dfischer/meteor-prerenderio) and I've got this line in my settings.json file
"PrerenderIO": {
"prerenderServiceUrl": "http://localhost:3033/"
}
However, when I run
curl http://localhost:3000/?_escaped_fragment_=
it returns nothing and I'm getting this message shown up on my meteor server log
res.send(status, body): Use res.status(status).send(body) instead
and it doesn't seem to be hitting the prerender server.
What is this message and why aren't I able to hit the prerender server?

Categories

Resources