我刚刚将一个 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.
服务器代码:
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']);
});
客户代码 index.html: 我包括这样的 socket.io:
<script src="/socket.io/socket.io.js"></script>
客户端代码 script.js:
var url = 'http://localhost:8080';
var socket = io.connect(url);
我该如何解决?