我正在尝试将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.如何建立这样的连接?
谢谢!
发布于 2014-08-10 20:35:27
这个问题并没有完全解决,但我能够通过恢复到常规的express.js+socket.io组合来克服它。
即使是使用此设置的跨域请求,头问题似乎也会平息下来。
https://stackoverflow.com/questions/25223521
复制相似问题