我一直在尝试为我的网站想出一个与 socket.io 很好地配合的解决方案。现在我有 apache 为我的网站提供服务(主要是在 php 中),我正在尝试使用 socket.io(节点)实现实时聊天支持功能。我能够让聊天功能单独工作(使用 express 并转到 wundertutor.com:8000)但是当我只是去 wundertutor.com(其中也包括聊天功能)时,我遇到了 CORS 问题(Cross -起源资源共享)。这是我的错误(在客户端):
XMLHttpRequest cannot load http://chat.wundertutor.com/socket.io/1/?t=1356421805823. Origin http://wundertutor.com is not allowed by Access-Control-Allow-Origin.
或者
XMLHttpRequest cannot load http://chat.wundertutor.com/socket.io/1/?t=1356422229000. Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.
取决于我是否在我的 app.js 中包含这行代码
io.set("origins","http://wundertutor.com");
基本上,我只想让我的节点应用程序成为我主站点的补充,但我真的不知道在哪里指定 CORS 参数。我已经尝试在我的 .htaccess 文件、app.js 以及客户端 javascript 中执行此操作,但都没有成功。
(另外,我觉得奇怪的另一件事是,当我访问 wundertutor.com:8000 时,我的节点应用程序正确打开了一个 websocket,但是当我尝试访问 wundertutor.com 时,它尝试使用 XHR 轮询,这最终导致这个CORS混乱)
任何建议将不胜感激!