Socket.io握手在我的站点上失败,但在localhost上失败.我不得不提供自定义握手,因为socket.io无法找到我的查询参数.
这是我在socket.service.js中的声明:
var ioSocket = io('https://my-site.rhcloud.com//?EIO=2&transport=polling&t=1414328625757-0&
token=' + Auth.getToken(), {
});
Run Code Online (Sandbox Code Playgroud)
以及我如何在服务器端捕获它:
socketio.use(function(socket, next) {
request.get('https://my-site.rhcloud.com/api/users/chan', {qs:{access_token:socket.handshake.query.token}}, function(err, me) {
if (err||!me.body|| me.body=='Unauthorized') {
if (!me) console.log('!me');
if (err) console.log(err);
next(err);
}
else {
// perfoming operations
next();
}
});
});
Run Code Online (Sandbox Code Playgroud)
这是我得到的信息:
WebSocket connection to 'wss://my-site.rhcloud.com/socket.io/?EIO=2&transport=websocket&t=…YwMX0.1F6ebfNxzoDPYffXGapGMzLFPJd-mfN0EexqZzXXo7A&sid=z0Jmrbgb7OS0nbqxAAAG' failed: Error during WebSocket handshake: Unexpected response code: 400
Run Code Online (Sandbox Code Playgroud)
我真的迷失在这里,并在没有任何成功的情况下深入挖掘谷歌.任何帮助将非常感激 !
Tho*_*ook 12
经过大量的搜索,我意识到问题来自Openshift.您必须指定要使用的端口套接字.看到这篇文章:https://blog.openshift.com/paas-websockets/
所以,我只需要写:
var ioSocket = io('http://my-site.rhcloud.com:8000, {
});
Run Code Online (Sandbox Code Playgroud)
Nginx代理使用以下配置解决了该问题:
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
Run Code Online (Sandbox Code Playgroud)
原来的解决方案在这里.它对我很有用(Ubuntu 14.4 + Plesk 12.5).
| 归档时间: |
|
| 查看次数: |
12184 次 |
| 最近记录: |