来自远程站点的源错误

来自远程站点的源错误

本文介绍了Socket.io access-control-allow=来自远程站点的源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从另一个站点访问 socket.io 服务器.它工作了几个星期,但现在我不断收到以下错误.从heroku上的服务器访问nodester上的服务器时会发生这种情况.错误是:

I am trying to access a socket.io server from another site. It worked for a few weeks but now I keep getting the following error. It happens when accessing a server on nodester from a server on heroku. The error is:

XMLHttpRequest cannot load http://site2.nodester.com/socket.io/xhr-polling//1311008802545.
Origin http://site1.heroku.com is not allowed by Access-Control-Allow-Origin.
Resource interpreted as Script but transferred with MIME type text/plain.
Uncaught SyntaxError: Unexpected identifier

这是我与套接字连接的方式:

Here's how I'm connecting with the socket:

socket = new io.Socket(
    'site2.nodester.com', {port: 80, rememberTransport: false}
);

这是服务器代码:

// requires

server = http.createServer(function(req, res){
    // server stuffs
}),

server.listen(8362);

var io = io.listen(server),

// io code

推荐答案

configure socket.io 仍然使用默认的 origins = * 或者至少把 origins = site1.heroku.com

Did you configure socket.io to still use default origins = * or at least put origins = site1.heroku.com

这篇关于Socket.io access-control-allow=来自远程站点的源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 21:58