Saturday, June 21, 2014

Configuring and Setting Up Nodejs, Sailsjs, Cloudflare, and Nginx, with Websockets

Hey everyone, I decided to start blogging some of the things I do. Today, I've slayed a beast, which consisted of a Linux box running Nodejs, Sailsjs, and Nginx. My goal was to use the awesome Sailsjs websockets. However, it simply wasn't working and my sockets were downgrading to ajax, making many request, and scaling poorly. Here is what I did to get them all working together.


1. Cloudflare: I had to create a subdomain that didn't have the cloudflare caching on.


 2. I needed to configure my Nginx sites-available file. 


3. Understanding that sails console does not automatically broadcast socket changes.



For those who haven't used sails and sockets much~ Here is how I set up the Nodejs Sailsjs stuff.


1. In the Terminal navigate to your project folder and do the following commands.


sails generate model messages body:text

sails generate controller messages

2. In the views folder, I simply modified homepage.ejs to this:



4.Start the sails server.

sails lift


I just like the boat

If this was useful or entertaining, please share and follow me on Twitter @jemiloii