socket.io client not connected to azure server created in socket.io - node.js

//this is my client code which is previously pointing to my local server which is on my Lan network.it work fine
//my server code i post on azure machine and run it run fine
//but it not connected to my below client
var socket = io.connect('http://104.222.195.120:4000');// azure ip add
socket.on('news', function (data) {//angular client for socket
$rootScope.top = JSON.parse(data);//top receive data
$scope.$apply(function () {
// $scope.newCustomers.push(data.customer);
// $scope.a1 = data;
});
});
//io.connect('http://104.222.195.120:4000') is need more than ip

If you're running your server in an Azure Web App, you're going to have issues because you're trying to listen on port 4000. Web Apps only allow for ports 80 and 443.
If you're running your server in an Azure VM, you have to open port 4000 to the outside world via network security group (or endpoint if doing a Classic VM deployment).

Related

How to make an Azure Service Bus Node.js client connect via HTTPS (port 443), not port 5671?

We are using the #azure/service-bus package to listen for Azure Service Bus messages in a Node.js application. Unfortunately the default port 5671 is blocked in our environment.
According to this documentation and this question the connectivity mode can be changed to HTTPS (port 443), at least from .NET (and maybe Java) like so:
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https;
How can we achieve the same in a Node.js based application?
For https support, you will need to use WebSockets. Try to create your Service Bus client using the code below:
const connectionString = 'your service bus connection string';
const connectionOptions = {
webSocketOptions: {
webSocket : WebSocket
}
};
const serviceBusClient = new ServiceBusClient(connectionString, connectionOptions);
Now you'll be connecting to your Service Bus using https over port 443 instead of AMQP using port 5671.
For more details, please see ServiceBusClientOptions and ServiceBusClient.

Accessing local database using Heroku

So I've developed a Node.js app that accesses an Oracle database (that can be accesssed by all connected clients) for connected users, and sends them push notifications depending on certain query results. I used the web-push API (details at https://www.npmjs.com/package/web-push) to send push notifications to the connected clients, who essentially send a subscription with an endpoint to the server, and receive notifications based off this data.
1) I can't seem to host this app over simple LAN using my IP address since it doesn't have SSL certificate (https extension) and service workers don't work.
2) I deployed the app using Heroku, and now can send push notifications to various clients, but am unable to access the database (throws me an error).
How do I connect to the oracle database when deployed on Heroku? Is there a workaround?
I use the following simple code to connect to my database:
connection = await oracledb.getConnection( {
user : <username>,
password : <password>,
connectString : <connectionString>
});
You can use service like ngrok which allows to access local port publicly.
The process of how to setup ngrok can be found in the link below
https://ngrok.com/docs
For example if I was running PostgreSQL server on my local machine and I want to expose that PostgreSQL server listening on the default port, I will run below command with ngrok
ngrok tcp 5432
And the tcp url & port that will be displayed after port is exposed successfully will be database host name & port respectively.
Its better to use oracle cloud services..ATP database is an always free feature..

Connect nodeJs app to on-premise server using Secure Gateway

I'm trying to connect from a nodejs webapp to a REST api hosted on premise. I bounded a Secure Gateway instance and created a destination on port 80 to the machine where the SG client for RHEL 6 is running.
The request is still throwing a Timeout exception.
Do I have to modify the nodejs application code in any way or the SG should allow me to access the REST api transparently?
Your Node.js app needs to talk to the Secure Gateway service and not the API directly. Where you establish a connection to your on-premise API, replace the host name and port number with the cloud host name and port number that you were given when you created the destination.
There is an npm module to help your app obtain that host name and port - https://www.npmjs.com/package/bluemix-secure-gateway
And an example - https://www.ibm.com/blogs/bluemix/2015/04/reaching-enterprise-backend-bluemix-secure-gateway-via-sdk-api/

Azure App Service - Detect Shutdown

I have a Node.js app hosted as an App Service on Microsoft Azure. Periodically, it shuts down. I'm trying to understand when this occurs. In attempt to do this, I'm sending myself an email on certain events.
Currently, I'm sending an email to myself when the app starts. Then, I try to send an email when the app service stops. I'm attempting this using the following code:
const app = require('./app');
const port = 1337;
const server = app.listen(port);
// Respond to the server starting.
server.on('listening', function() {
sendEmail('App Service - Listening', 'Web site server listening');
});
server.on('close', function() {
sendEmail('App Service - Closed', 'Web site server closed.');
});
process.on ('SIGTERM', function() {
sendEmail('App Service - Exited', 'Process exited (via SIGTERM)');
});
process.on ('SIGINT', function() {
sendEmail('App Service - Exited', 'Process exited (via SIGINT)');
});
process.on('exit', function() {
sendEmail('App Service - Exited', 'Process exited');
});
Please assume the sendEmail function exists and works. As mentioned, I'm successfully getting an email when the app is listening. However, I never receive one when the app goes to sleep/stops listening.
Am I missing something?
If your post code is hosted on Azure Web Apps, you need to modify your port to process.env.port to make your node.js application run on Azure.
As Azure Web Apps use IIS to handle mapping scripts, and use a pipe port to translate http requests. And Azure Web Apps only expose 80 and 443 port to public.
Meanwhile, you can modify your prot to process.env.port||1337 to make it both run Azure and local.
update
Always On. By default, web apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time. If your app runs continuous web jobs, you should enable Always On, or the web jobs may not run reliably.
You can config this setting on Azure portal:
refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/ for more.
It could be an uncaught exception, try this one to catch them:
process.on('uncaughtException', function(err) {
console.log(err);
});

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