Azure Web Site starting my Hapi Node.js site with socket protocol - javascript

Whenever I deploy my Hapi.js web application to azure, it starts the server using the socket protocol (see output below).
socket:\\.\pipe\b5c0af85-9393-4dcb-bd9a-3ba9b41ed6fb
GET /
GET /{param*}
GET /api/employees
POST /api/employees
GET /api/employees/{id}
PUT /api/employees/{id}
DELETE /api/employees/{id}
POST /api/worklog
GET /login
POST /login
Hapi server started # socket:\\.\pipe\b5c0af85-9393-4dcb-bd9a-3ba9b41ed6fb
150914/214730.270, [response], socket:\\.\pipe\b5c0af85-9393-4dcb-bd9a-3ba9b41ed6fb: [1;32mget[0m / {} [32m200[0m (316ms)
However, whenever I am running this locally, it starts using http... I have not run into this issue using express or loopback, only Hapi. Is there some sort of configuration that I am missing? This is the server.connection function:
var server = new Hapi.Server();
var host = process.env.host || '0.0.0.0';
var port = process.env.port || 3000;
server.connection({host: host, port: port});
The reason this is a big deal is because I cannot pass socket://*<mydoamin>* to google as a callback URI for OAuth.

You shouldn't need to pass socket://<domain> to google, you'd pass the normal https://yourDomain.com or even the https://yourSiteName.azurewebsites.net to Google for OAuth callback and it should work as you would expect.
The fact that the node application is listening on a pipe rather than a normal tcp socket is just an implementation detail of iisnode. Basically the problem is that node has it's own webserver so you can't use it with other webservers like IIS, Apache, nginx, etc. iisnode bridges the gap between IIS and node in that it allows IIS to listen to the HTTP port on the machine 80 and when IIS gets a request on that port, it just forwards it to the node process that's listening on a named pipe. This allows you to manage your sites in IIS as you normally would on a Windows Server machine, while actually writing your app in node.
You can think of it as 2 webservers running on the box, one (IIS) is acting as a proxy for the other (node) where all the work is actually happening. The fact that the iisnode developer chose to use a named pipe instead of a normal tcp socket is odd (though kind of understandable since you can't easily reserve a port per se as you can a pipe), but it's the way it is.

Related

Node Server With NGINX

I have node js server that has a server which listens 8000 port and a socket.io connection working on that server. This socket connection creates a communication with a ReactJS app which is not a point of this question. So I have 2 project folders
1. project-server
2. project-web-react
Project server only answers socketio request and does not render a HTML or something else. It only works on terminal. I want to ask whether is it useful to encapsulate my project-server with Nginx? So the requests are handled by Nginx ? Or is it out of the Nginx's purpose?
I would never have an application server run directly connected through internet since there are always a bunch of unknowns with them (scaling, standard compliance etc), so I would recommend you to run a proxy like nginx in front of your app. This also makes it easy to add certificates and do load balancing / caching. It just adds flexibility and some security.

Express.js server with Apache Tomcat

I am making a sample web application in node.js using express.js. I am getting a little confused when using apache-tomcat as my web server. I have two doubts:
When i run apache-tomcat as a web server and my express.js server is providing me services at port number 4000, how does it know at which port to listen to tomcat web server. and what if i have multiple instances of tomcat running on localhost, how will it know which instance of the server to connect to.
app.listen(port, "127.0.0.1");
And how does the following line of code works:
var server = app.listen(4000, function() {
var host = server.address().address;
var port = server.address().port;
console.log('server listeninig at http://%s:%s', host, port);
});
Why do we need to take help of apache tomcat or other web servers if we can provide web services using express.js only.
I don't believe that combining express.js (simple web server for Node.JS platform) and Apache Tomcat (Servlet container from JVM world) make sense at all.
I bet that you are confusing Apache Web Server with Apache Tomcat. They are two completely separate projects. If that is the case than notice that Apache Web Server or Nginx HTTP servers are often used with express.js as reverse proxies. This combination is often used to match security and performance (e.g. caching) requirements needed for PROD grade app.
To answer your question, no don't combine express.js with Apache Tomcat. If you are just starting playing with express.js, use it standalone. If it turns to be a app that should run in production, you will need to operationalize it, which would probably include considerations around combining it with some HTTP server.

How to run node.js in my web site server not my pc local server

Last 2 days I spent more time and read 50+ articles and video to understand node.js and after installation now I can see the result in browser by http//:localhost:3000/ But I have confused in many case that I describe below.
I do all of my work in my share hosting server where I my keep my web site: www.myweb.com
In every article about node.js, they are teaching how to get a result by below code in a browser by http//:localhost:3000/ in local pc server.
test.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');
But My Question:
If I use http//:www.myweb.com/test.js` in my browser, What will be the above code?
In case of local pc we write on npm node test.js, But In case of hosting server when any clint open the page like http//:www.myweb.com/test.js How to work it?
In case of php we used include ("head.php") to got something from that page But In this case How to make a call on node.js.
Well, what you need to do is understand how http web servers works.
Usually, on your remote machine (your server), you have an instance of a web server (ex : apache) running, which is listening to port 80 (standard port for http requests). It will handle every request made on that port, and manage routing to use the correct php/html file.
Then, it will run the php code server-side, to render an html file and serve it to the server. So the client will not see the php code at all.
Let's talk about Node.js. Node is an application that runs javascript code server-side, and can run an http server with using some modules. But the javascript code will never be shown to your client, he will only get the http response you send him (typically, the html page).
So now, with node.js, you need to do the same as the apache server did, by creating the http server. First, what you have to know is that not that many website host are offering node.js, or even console access. They usually serve the php/html files you put in the configured folder, and that's basically it. What you need is either a virtual machine, or a server on which you can install node.js and run it, or use a node.js hosting service, like heroku or nodejitsu to host your node.js http server.
So, to create the node.js http server, you need to create an http server (as you did in your code), and make it listen to port 80. Now, every http request send to your server will be handled by your node.js instance. Then, you can do anything you want with that request.
I hope I haven't been to messy.
You need to install NodeJS on the server. If this is shared hosting where you cannot install additional software then you will be unable to use NodeJS. In that case contact support of your web hosting company and inquire about NodeJS support.
On the other hand, if you do have root user or super user rights on a system, you can install NodeJS. For example for on CentOS/RHEL systems you can install using yum with the following commands.
sudo yum install epel-release
sudo yum install npm
For some of the other distributions of Linux: http://ask.xmodulo.com/install-node-js-linux.html
To access Node applications from your PC to the server, you also need to open a port in the server firewall that your Node aplication uses.

Setting laravel to work on a port number?

I am working with nodejs, expressjs, and socket.io I am triggering events on my web app with a mobile phone over the nodejs server.
The app is built on javascript but I am using laravel to store data into a database. I am new to nodejs so I am pretty sure if I wanted, I think I could cut out php and just use the whole app with nodejs, but I don't want to. I like laravel and php and it's alread setup, so let me explain my problem.
laravel is installed on my server http://example.com/public/ laravel's index.php is here. My routes for my data base resources are http://example.com/public/feeds. I can access this fine, but if I want to access my nodejs server I need to use http://example.com:3000 which obviously causes a problem.
The nodejs/expressjs files are inside http://example.com/public/MY-FILES-HERE but since the nodejs dispatches on http://example.com:3000 this throws my laravel routes off.
So what I am asking is how do I get it all to work well with eachother? I assume I need to setup a port somehow in laravel.
EDIT: So I am new to the port, and I didnt know there is already a default port set (80). My laravel install is on port 80, and inside here I can listen to calls from port 3000 using socket.io. I did not know that, so I have a page http://my-server-ip:3000/test which has one button and a script that sends the event to the nodejs server and that responds to my script which listens to events on port 3000 and executes a function. Cool stuff here, I hope I made sense I am very new.
Not quite sure what you mean by
this throws my laravel routes off
In a situation where you want to host multiple servers on port 80 from the same machine you might want to consider a reverse proxy. I recommend nginx for this.(http://www.cyberciti.biz/tips/using-nginx-as-reverse-proxy.html). Nginx will listen to port 80.
Then you setup a subdomain eg. node.example.com for the node.js service.
In the reverse proxy you listen for node.example.com on port 80 and direct that to port 3000. You set up Laravel/Apache? to listen on port 4000 and have nginx listen for www.example.com on port 80 and direct that to port 4000.
Is this what you are after?

Dotcloud www and TCP in single app -

I'm trying to get a nodejs socket server running that will allow remote communication between two clients running a Flash game that communicates using a custom protocol. Due to Flash security restrictions, it seems that the socket server must be running on the same host as the web server that servers the Flash game. I've been continuously getting the following error:
The service crashed at startup or is listening to the wrong port. It failed to respond on port "nodejs" (8080) within 30 seconds
What I need is a way to run my nodeJS server code, while simultaneously serve the flash files.
I'm using the environment JSON variables to determine what port to listen on, and my YML is similar to the one discussed here but no luck...
Just wondering if I can get some info on how to create a working socket server/web server that will work for this (or if it is actually possible)
You can use the following dotcloud.yml file:
www:
type: nodejs
ports:
mything: tcp
Then in your Node.js app, you can bind a HTTP server to port 8080, and an arbitrary TCP server to the port contained by environment variable $PORT_MYTHING. Then run dotcloud info on your service; in the ports section, you will see something like this:
- name: mything
url: tcp://myapp-johndoe.dotcloud.com:12345
From now on, if you connect to myapp-johndoe.dotcloud.com on port 12345, you will actually connect to $PORT_MYTHING in your application.
I hope that it makes sense, and that it is what you were looking for!

Categories