0

我正在尝试设置 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.

如何建立这样的连接?

谢谢!

4

1 回答 1

0

这个问题并没有完全解决,但我能够通过恢复到常规的 express.js+socket.io 组合来克服。

即使对于使用此设置的跨域请求,标头问题似乎也平静下来了。

于 2014-08-10T12:35:27.323 回答