AppFog node.js客户端无法加载socket.io

Bas*_*vis 1 node.js socket.io appfog

我刚刚将一个node.js站点部署到了AppFog.当我转到"http:// localhost:8080"时,它在本地工作正常,但当我到达AppFog上的那个时:http://bandwithfriends.aws.af.cm/ 我收到以下Chrome控制台错误:

XMLHttpRequest cannot load http://localhost:8080/socket.io/1/?t=1357769454152. Origin http://bandwithfriends.aws.af.cm is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)

服务器代码:

var app = require('http').createServer(handler),
    io = require('socket.io').listen(app),
    static = require('node-static'); // for serving files

// This will make all the files in the current folder
// accessible from the web
var fileServer = new static.Server('./');


app.listen(process.env.VCAP_APP_PORT || 8080);

io.configure('development', function(){
  io.set('transports', ['xhr-polling']);
});
Run Code Online (Sandbox Code Playgroud)

CLIENT CODE index.html: 我包括socket.io,如下所示:

<script src="/socket.io/socket.io.js"></script>
Run Code Online (Sandbox Code Playgroud)

客户端代码script.js:

var url = 'http://localhost:8080';
var socket = io.connect(url);
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

Bas*_*vis 5

我需要做的就是删除客户端代码上的url:

var socket = io.connect();
Run Code Online (Sandbox Code Playgroud)

希望这有助于其他人遇到同样的问题!