Rails 3.1 在 Ubuntu 11.10 上与 Socket.io/Juggernaut 配合使用

发布于 2024-12-18 05:40:02 字数 968 浏览 7 评论 0原文

我无法让 Juggernaut/Socket.IO 在 Windows 上运行,所以我尝试让它在 Linux 上运行。我不太了解 Linux(或者 Rails)。我无法让 Socket.io/Juggernaut 在我的 Rails 服务器上运行。它在 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
  • NodeJS 0.4.9
  • NPM 0.2.19
  • Socket.IO v?.? (我今天刚刚运行 npm install socket.io)
  • Juggernaut v?.? (我今天刚刚运行了 npm install juggernaut)
  • 在 Firefox 和 Chrome 中进行了测试

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2024-12-25 05:40:02

这看起来像是 CORS 问题,浏览器不允许向另一个源(在本例中为端口 8080)发出 AJAX 请求。

您可能需要在 Socket.IO 中设置 CORS 标头。

我找到了这个答案: https://stackoverflow.com/a/10423354/351937

要了解有关 CORS 的更多信息,请看看这里:http://enable-cors.org/ 和当然是谷歌。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文