2

I generated a node.js app using Yeomans angular-fullstack generator. Everything worked fine except the use of socket.io. After uploading my app to openshift using angular-fullstack:openshift, I got informed that I have to:

Openshift websockets use port 8000, you will need to update the client to connect to the correct port for sockets to work. in /client/app/components/socket/socket.service: var ioSocket = io.connect('http://my-domain.rhcloud.com/:8000')"

I dont know where to do this. I am using socket.io version 1.0.6 which is shown inside package.json file.

==> app-root/logs/nodejs.log <== /var/lib/openshift/xxx/app-root/runtime/repo/server/config/socketio.js:41 socket.address = socket.handshake.address.address + ':' + ^ TypeError: Cannot read property 'address' of null at Namespace. (/var/lib/openshift/xxx/app-root/runtime/repo/server/config/socketio.js:41:46) at Namespace.EventEmitter.emit (events.js:95:17) at Namespace.emit (/var/lib/openshift/xxx/app-root/runtime/repo/node_modules/socket.io/lib/namespace.js:205:10) at /var/lib/openshift/xxx/app-root/runtime/repo/node_modules/socket.io/lib/namespace.js:172:14 at process._tickCallback (node.js:415:13) DEBUG: Program node server/app.js exited with code 8 DEBUG: Starting child process with 'node server/app.js'

By the way, the app, including socket.io, works fine on my local development machine!

Thanks for any help! Fall.Guy

Fall.Guy
  • 41
  • 3

2 Answers2

2

My working solution is now:

I changed the creation of the openshift app to "not create a scalable app" (I disabled the -s switch in the yo angular-fullstack:openshift command)

After that, I changed the connection of socket.io to:

var ioSocket = io('http://my-domain.rhcloud.com:8000', {
  // Send auth token on connection, you will need to DI the Auth service above
  // 'query': 'token=' + Auth.getToken()
});

in the "/client/components/socket/socket.service.js" file. Socket.io works now fine!

Fall.Guy
  • 41
  • 3
0

I'm not sure why openshift requires this, but you just need to modify your client code.

In your client side code, you should have something like this:

var socket = io();

You'll apparently need to update it to:

var socket = io('http://mywebsite.com:8000');

It's worth noting that there are plenty of other hosting providers (even free) which don't require you to jump through these hoops.

Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76