Wednesday, August 14, 2013

Starting a new Node.js Socket.io Jade Angular Express Site on OpenShift :D

So to start a new site I went to btford's angular-socket-io-seed and downloaded the zip. He seems to have changed his package management over to bower, and alternative to npm, though there seems to be disagreement on stackoverflow as to which is better. Whatever. Here is the definitive article on package management that addresses nom, bower, et al. The whole idea is to get the Amazon AWS SDK node package working with it.

I made a new node site on OpenShift, pulled the repo, then deleted everything and copied the angular-socket-io-seed. Then I globally installed bower, and locally installed socket-io and express in my new app. I renamed app.js to server.js to satisfy OpenShift's launcher. Also had to npm install Jade.

Next I had to change in server.js:

self.ipaddress = process.env.OPENSHIFT_NODEJS_IP;

self.port = process.env.OPENSHIFT_NODEJS_PORT || 8080;

This ends up looking like this:

app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);

app.set('address', process.env.OPENSHIFT_NODEJS_IP);

Added app.get('address'), to server.listen.

That worked, except the time isn't showing up. Well it's on a severe delay.

So I nav'd to /public in my project and did:

bower install angular-socket-io

This is to update that since it was 0.0.2 in the project but current is 0.2.0, and I think it was having to download a dependency causing the delay. Nope, the delay was due to the fact rhcloud does not support websockets on the default port! Therefore it falls back on XHR polling just like Heroku does, at least by default. But as of December 2012 they had a preview with websockets working. You have to use port 8000 for http or port 8443 for https for it to work evidently.

So therefore... what I had to do is in my client app.js I had to add this:

config(function ($routeProvider, $locationProvider,

//this as per the angular-socket-io documentation to get it to connect to the port 8000:

socketProvider) {

var mySocket = io.connect('http://myURL:8000');

socketProvider.ioSocket(mySocket);

Because otherwise it will still default to the regular port and go back to nasty XHR polling.

I thought of using a proxy module for node but this worked so hey. It goes to show you. There's usually a non-obvious built-in solution to obvious problems.

ZOMG I had to bower install angular-cookies ... for some reason it's not already there... WTF!?

Then I had to drag the angular-cookies files into the angular main folder... they couldn't be in the separate folders that it makes for your ass. WTF WTF. It was because I wasn't loading scripts in order in my index.jade file.

Now I keep getting the error:

/Users/qwerqwer/Documents/Dev/node projects/sithari/routes/socket.js:45

thisApp.thisStore.get(sid, function(err, gotsession) {

^

TypeError: Cannot call method 'get' of undefined

Why the heck is it undefined?

Because I needed to npm install Async.

No comments:

Post a Comment