I am writing a rails app, and I would like to use node.js and socket.io to integrate a chat feature into my app. I plan on having my rails app deployed on one server, and my chat deployed on a much smaller server (to save money). My reasoning for this is, it is OK if a chat message takes 30s to send, but it is not OK for a page to take 30s to load.
Anyway, in order for this to work, I need Rails to server the socket.io client files. If my small node server serves the client files, then the small server will bottleneck the larger one. I have a basic chat prototype up and running, but it only works with node serving the client files. What do I have to do in order to have rails serve the client files?
Thanks in advanced.
So here is the solution I decided upon. Instead of figuring out what client files I need to serve, I decided to let the Node server handle the client javascript. In order to ensure that the Node server does not bottleneck the Rails server, I lazy load the socket.io-client file. The relevant coffee script is:
$ ->
$.getScript('http://localhost:8080/socket.io/socket.io.js')
.done (script, textStatus) ->
socket = io.connect('http://localhost:8080')
setupSocket(socket)
Where http://localhost:8080 is your Node host/port. setupSocket is a function I wrote that handles setting all the event handlers.
Most probably you are running into the "Same Origin Policy" restriction. (Check your console log) Your main page is downloaded from the RoR host, so your scripts can only initiate a connection to that host.
In other words, this may not be possible.