首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跨域socket.io连接express.io服务器失败

跨域socket.io连接express.io服务器失败
EN

Stack Overflow用户
提问于 2014-08-10 06:06:16
回答 1查看 422关注 0票数 0

我正在尝试将socket.io设置为连接到具有不同来源的流服务器。

该服务器是一个专用的流服务器,是更大设置的一部分,基于Express.io:

代码语言:javascript
复制
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);
});

尝试打开连接会导致以下错误:

代码语言:javascript
复制
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.

如何建立这样的连接?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2014-08-10 20:35:27

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

即使是使用此设置的跨域请求,头问题似乎也会平息下来。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25223521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档