简体   繁体   中英

Cross-Origin socket.io connection to express.io server fails

I'm trying to setup socket.io to connect to a stream server with a different origin.

The server is a dedicated stream server as part of a larger setup and is based on 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);
});

Trying to open a connection it results in the following error:

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.

How can I set up such a connection?

Thanks!

The issue is not exactly fixed but I was able to overcome is by reverting to a regular express.js+socket.io combo.

There header issue seems to quiet down even for Cross-Origin requests with this setup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM