Nodejs Loopback how to access api end points on live server? - node.js

I'm trying to deploy a Loopback project to live server, all works well on local. On server, after running node ., I get the console log of:
Web server listening at: http://domainname:3000
Browse your REST API at http://domainname:3000/explorer
So it looks like the server is running.
Problem is that I get no response from the server. Neither from domain:3000 or /explorer or any endpoint I created.
Does anyone know what might be the issue?
Thank you very much

I had a similar problem when I was trying to deploy my code. Some of the possible solutions to the problem depending on where and how you are deploying it-
Check if your security group allows connections on port 3000. AWS EC2 by default closes all ports except port 80. You might have to add an exception to your security group and allow port 3000 to be accessed from everywhere.
If you are using a container, check if your container has the ports open and if the container port is accessible by the hardware hosting the container. On Azure, I faced this problem as Azure Web App Container Service by default only listens to port 80 and 8080. So I had to modify my code such that it can use the default NODE_ENV.PORT or 8080.

Related

What is the right way to make a call when two servers run on different ports

I have a backend node/express app. Currently, my JWT server is running say on port 4000 and the backend is running on port 8080 (they both running on the same server). So when I want to make a request from backend server to JWT server it is quite straightforward, just put the url of the fetch request to be http://localhost:4000 and it works. However, I am a little confused for the case when this app is in Cloud Run (prod environment). I apologize if my question sounds dumb, but how do I make the similar call when the environment is production, in my case Cloud Run? Do I have to assign the public url of my my Cloud Run server (for example, https://some-backend-612y2zfwwq-uc.a.run.app/4000 or will localhost work exactly the same even in the production?
You have 2 services (processes) and each will need to be containerized and should be containerized separately to deploy to Cloud Run, i.e. two containers, one for the backend and another for the JWT service.
It is good practice to run one process per container and because Cloud Run only permits a single TCP socket (port) per Cloud Run service, you will need to run each service as a separate Cloud Run service because each wants to publish its own port.
Cloud Run also requires that services listen on the environment variable PORT value and this defaults to 8080. So, you would also need tailor your services so that each of them would listen on whatever value is defined by PORT.
Cloud Run services may also be deployed either to require authentication or to not use authentication (i.e. be public). You will need to decide how your 2 services interact including whether e.g. your backend service authenticates to the JWT service.
There is no need to apologize for asking questions on Stack overflow. This site is for developers to ask questions.
To get it working on a production environment, you usually expose your port on the port 80, which allows users and other applications to just make a request to whatever url you deploy your application to. For example, you usually go to google.com not google.com:3000 or whatever.
So you'd open up that port 80 to external requests and your other application would just make a call to the url of the production environment.
You technically don't have to port your port 4000 (wherever the port is deployed to 80) but that is very common.
This is also a very simple explanation of what are some common practices.
If you want to deploy your application on the same environment or network, you can check it out if it works using a docker network: https://www.tutorialworks.com/container-networking/. And you can deploy the whole network on prod where you won't really have to deal with specifying specific production urls.

Domain creation on windows machine via IIS

I wanted to create and map a domain(ex: site1.domain1.com) locally to the server running on localhost with some port, I've been trying to do via IIS, but raising port conflict issue, unable to create and start site domain while web server is up since the port is already occupied and vice versa.
Could you please provide how to resolve this or any other simple way to create and map the domain with the server running on localhost.

Application Error message when browsing Azure deployed web app

I created a simple web app (serverless) and deployed the web app using Azure App Service VS Code extension. I chose Linus + Node LTS environment. I configured deployment source to a local Git repo (also tried remote GitHub repo) and deployed. The deployment shows successful message. But when I browse the site, it throws a message (after 3-4 mins) that there was an ":( Application error". The admin diagnostics link doesn't show any error. Any reason why this could be happening?
Where can I find error details?
The web app compiles/runs fine on the local host.
Enable Log Streamming, then you'll be able to figure out what the problem is:
https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs
As another option, you can also instrument your application with Application Insights:
https://learn.microsoft.com/en-us/azure/azure-monitor/app/nodejs
On Azure WebApps, the container/application must respond to HTTP pings on the required port (check docker run command in the Log Stream) within 230 seconds, by default.
For a NodeJS app, you'd need to start the server in the following way:
const port = process.env.PORT || 1337;
server.listen(port);
Try deploying the sample available here:
https://github.com/Azure-Samples/nodejs-docs-hello-world
If that does not help, enable App Service Logs and check for any errors in the Log Stream.
I had created a NodeJS app which integrates with Application Insights some days back:
https://github.com/gkgaurav31/nodejs-application-insights-test-app
change your listen port either 8080 or 1337
By default, NodeJS webapp runs on port 8080. You are either running your port on some other port (Ex: 3000 or so) and then deploying it to webapp. Try changing your port in NodeJS app to 8080 and it should work.

AWS EC2 instance access internal server

In my Amazon EC2 instance I have a Pyramid server as well as a NodeJS server running. The NodeJS server acts as the frontend and I updated my security groups so I can use the public DNS to view the page.
The Pyramid server acts as a backend and the frontend accesses it by http://0.0.0.0:8002/. But when I do an http call to the backend I get a Failed to load resource: net::ERR_ADDRESS_INVALID error message.
Do I need to add a rule to the security groups, or update the iptables, or something?
If both of these services are running on the same server, you shouldn't be sending network traffic out of the server and back, so security groups will not be an issue here.
The question is, why are you using 0.0.0.0 here? I think you probably configured the Pyramid server to listen on 0.0.0.0, which really means "listen on all IP addresses". However you need to be using http://127.0.0.1:8002/ or http://localhost:8002/ in order to connect to the service from another service running on the same server.

Starting new port on Amazon Ec2 free tier for socket io

I am using Amazon EC2 service for the web purpose. I have a web application which is hosted on apache i.e port 80. Now i am running a node instance on port 3000 and when i load my website.
io.connect('http:IP ADDRESS:3000');
This code tries to connect to my port. On server side my instance is started. But when i load my we application, this doesnt connect to server.
I was wondering do i need to update my configuration or is there any network settings i need to do ?
Try adding your port in your defined security group.
Follow http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-network-security.html#concepts-security for more reference.

Resources