Cant connect azureweb app to node server, resulting in net::ERR_CONNECTION_REFUSED - node.js

I am using node.js and react and have deployed to the azure app service,
the startup command is pm2 serve /home/site/wwwroot --no-daemon --spa which works
However when I visit the website and visit a page that needs to load images from a database or perform any http requests, the app can't connect to the node.js server and I get the error:
https://boobah.azurewebsites.net:8080/requests/therapists net::ERR_CONNECTION_TIMED_OUT
The call I make in my code to load the data to the page is this:
await axios.get('https://boobah.azurewebsites.net:8080/requests/therapists')
which works locally just by changing the domain to localhost and on port 3000.
Can anyone please help me for why this is not loading any data to the deployed azure app ?
Thanks you

Related

My Ionic app can't access my local Node server from Android emulator

I'm trying to run for the first time my React/Ionic app on an Android Emulator using Capacitor. The app should connect to my local Node server using Axios.
While my app started successfully on the emulator, all server requests failed with Msg: Error: Network Error
Here's the steps that I did:
I configured Axios to connect to http://10.0.2.2:3001 instead of localhost, but the requests still fail
I opened the url http://10.0.2.2:3001/api in the Android Emulator Chrome browser, and it succeeded in connecting to my server and returning a response
I tried adding to my capacitor.config.json file the following conf, but my app still fails
"server": {
"allowNavigation": ["10.0.2.2"]
}
Would you have other advices I should try to make my app connect to my local server? Thank you
After searching, I found the solution in another SO question :
The problem comes from the fact the my app uses http instead of https requests which Android forbids by default, starting with API level 28.
To allow http requests, I added android:usesCleartextTraffic="true" to my app's AndroidManifest.xml
Reference: https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic
if you use instances on cloud, modify host file, on linux the rute is : /etc/hosts
add this line:
localhost < ip-public-your-instance >

How to access AngularJS application on Azure Virtual Machine?

I've both NodeJS and AngularJS applications. I'm using npm install to download the app's dependencies for both the application. The NodeJS application runs on port 4000 and AngularJS application runs on port 4200. I can access APIs from NodeJS application in the browser and cannot access the application's UI(AngularJS) in the browser. I have deployed these applications on Azure Virtual Machine.
I have opened the ports 4000 and 4200 in the network settings of Azure VM. I'm using npm start command to start both the applications. NodeJS working fine as like in the local machine but not the same case with AngularJS. There is no errors or warnings from AngularJS side. It shows that the app is listening on http://localhost:4200/ and it is not accessible.
In this case, you need to run ng serve --host 0.0.0.0 to allow that your AngularJS application is listening on 0.0.0.0 for outside connecting. You could refer to this How to allow access outside localhost
Try using:
ng serve --open --host 0.0.0.0 --disable-host-check

PeerJS Server 404 on Azure

I'm trying to deploy a PeerJS server on Azure. On my kudu console, running
node peerjs --port 9000
returns
Started PeerServer on ::, port: 9000, path: / (v. 0.2.8)
However, when I try to connect to the server from my client code, I get a 404. Going directly to appname.azurewebsites.net/peerjs/id in my browser also returns a 404.
I see inside their package.json file, they run
bin/peerjs --port ${PORT:=9000}
instead of just passing in 9000 directly; I assume this is an environment variable. However, trying to run this on Azure gives
Error: Error: listen EACCES ${PORT:=9000}
which I assume means Azure doesn't recognize ${PORT:=9000} as a valid port.
I know for a fact there's nothing wrong with my client side code because a) I copied it directly from PeerJS's website, and b) everything works correctly when I deployed PeerJS to Heroku. It's only not running on Azure.
Other things I've tried: I edited peerjs in the bin folder to use process.env.PORT instead of what's passed in via the command line, but that didn't work, giving the same EACCES error. When I tried to console.log(process.env.PORT), I got undefined. None of my Google searches have turned up any solutions, although this person (Custom PeerJs Server giving ERR_CONNECTION_TIMED_OUT) seems to have a similar error, not on Azure.
Azure App Service doesn't allow us to listen on a customer port. We need to use process.env.PORT instead. See Listen additional port Microsoft Azure Nodejs.
Azure App Service (on Windows platform) runs on Microsoft IIS. So we need to put the app files to its virtual directory (D:\home\site\wwwroot) and no longer need to manually run the app via the Kudu console.
In this case, you first need to install the library under app's root:
npm install peer
And then create a file named index.js or app.js with following content and put it to /wwwroot folder:
var PeerServer = require('peer').PeerServer;
var server = PeerServer({port: process.env.PORT, path: '/'});
As #Mikkel mentioned in a comment, PeerServer uses WebSocket protocol, so Web Sockets should be enabled in the Azure portal like this:
You also need to check out this post to add a web.config file for your app if it has not been created yet.
This will be a firewall problem... You will need to open port 9000 in your Azure settings panel.
From the machine itself, open up a browser to http://localhost:9000/ or http://localhost:9000/peerjs and you should see the standard Peerjs server JSON output.
Or if you only have command line, try curl http://localhost:9000/ or http://localhost:9000/peerjs

can not visit the web app made of angular cli on the digitalocean

I have built a simple web app using angular-cli 2,it works well in the local machine. now i tried to deploy it onto a digitalocean server,
however when going to the web server link with http://ip address:4200, i can't visit the web app.
Note: I can make sure the firewall is open to the web application on that port since in ufw status shows 4200 ALLOW Anywhere
You need to serve the actual ip address of the server, by default ng serve will use the loopback address. You can achieve this with:
ng serve --host 0.0.0.0

Difficulties connecting to socket.io server with Ionic

An overview of my setup:
A socket.io/node server is being hosted/ran on a computer in my local network.
An Ionic app is attempting to connect to the socket.io/node server to send/receive messages.
If I run the app in the browser with 'ionic serve', I am able to connect to the socket.io/node server successfully.
If I run the app in the emulator or on my device, I am only able to connect to the socket.io/node server if I add the -l (livereload) flag (ionic run android -l).
Originally, I hosted the node server on a heroku instance. I had no troubles connecting with this setup from browser, phone, or emulator. I had to switch to running the node server on a local computer so I have access to a local database.
Any ideas what is going on?
I fixed it by adding 'http://' to the beginning of the connection string.
Not sure why Ionic's livereload enabled me to connect without the 'http'

Resources