我正在尝试设置socket.io以连接到具有不同来源的流服务器。
服务器是专用的流服务器,是大型设置的一部分,基于Express.io:
var express = require('express.io'),
config = require('./config'),
app = express().http().io();
app.io.set('origin','*:*');
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
res.header("Access-Control-Allow-Methods", 'GET, PUT, POST, DELETE, HEAD', 'OPTIONS');
// Tried with and without this header
res.header('Access-Control-Allow-Credentials', false);
next();
});
app.io.route('ready', function(req) {
req.io.emit('talk', {
message: 'io event from an io route on the server'
});
});
app.listen(4000, function(){
console.log('Listening on port ' + config.port);
});
尝试打开连接会导致以下错误:
http://localhost:4000/?EIO=2&transport=polling&t=1407621822859-65.
A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.
Origin 'http://localhost:8080' is therefore not allowed access.
如何设置此类连接?
谢谢!
答案 0 :(得分:0)
问题并没有完全解决,但我能够克服的是恢复 一个普通的express.js + socket.io combo。
即使对于具有此设置的Cross-Origin请求,标题问题似乎也很平静。