我无法让 Juggernaut/Socket.IO 在 Windows 上运行,所以我试着让它在 Linux 上运行。我不太了解 Linux(或 Rails)。我无法在我的 Rails 服务器上运行 Socket.io/Juggernaut。它在 OS X 上工作正常(所以我知道它在工作)。
安装完所有内容后,我执行以下操作:
/rails/app/path/rails s
redis-server
juggernaut # output is: info - socket.io started
所以我猜这行得通。现在,当我运行一个使用 Juggernaut 的窗口时,我在 Chrome Javascript 控制台中收到以下错误:
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
软件信息:
- Ubuntu 11.10
- ruby 1.9.2
- rails 3.1.1
- 节点 0.4.9
- NPM 0.2.19
- Socket.IO v?.? (我今天刚刚运行了 npm install socket.io)
- 剑圣 v?.? (我今天刚刚运行了 npm install juggernaut)
- 在 Firefox 和 Chrome 中测试
最佳答案
这看起来像是一个 CORS 问题,浏览器不允许对另一个来源(在本例中为端口 8080)的 AJAX 请求。
您可能需要在 Socket.IO 中设置 CORS header 。
我找到了这个答案:https://stackoverflow.com/a/10423354/351937
要了解有关 CORS 的更多信息,请查看此处:http://enable-cors.org/当然还有谷歌。
关于ruby-on-rails - Rails 3.1 在 Ubuntu 11.10 上使用 Socket.io/Juggernaut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8283255/