Rails 3.1 working with Socket.io/Juggernaut on Ubuntu 11.10

611 Views Asked by At

I couldn't get Juggernaut/Socket.IO running on Windows so I took a shot at getting it running on Linux. I don't know much Linux (or Rails for that matter). I can't get Socket.io/Juggernaut working on my Rails server. It works OK on OS X (so I know it's working).

After everything installed, I do the following:

/rails/app/path/rails s
redis-server
juggernaut # output is: info  - socket.io started

So I'm guessing that works OK. Now, when I run a window that uses Juggernaut, I get the following error in the Chrome Javascript Console:

XMLHttpRequest cannot load http://localhost:8080/socket.io/xhr-polling//1322359666443. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.
Resource interpreted as Script but transferred with MIME type text/plain.
Uncaught SyntaxError: Unexpected identifier

Software information:

  • Ubuntu 11.10
  • Ruby 1.9.2
  • Rails 3.1.1
  • NodeJS 0.4.9
  • NPM 0.2.19
  • Socket.IO v?.? (I just ran npm install socket.io today)
  • Juggernaut v?.? (I just ran npm install juggernaut today)
  • Tested in both Firefox and Chrome
1

There are 1 best solutions below

0
On BEST ANSWER

This looks like a CORS issue, where the browser won't allow an AJAX request to another origin (in this case port 8080).

You might need to set your CORS headers in Socket.IO.

I found this answer: https://stackoverflow.com/a/10423354/351937

To find out more about CORS, have a look here: http://enable-cors.org/ and Google of course.