[英]ember-cli-mirage redirects socket.io client, which is injected in mirage
the issue that occurs here, is that, when i connect between sample socekt.io client with this socket.io server by node.js ( just running two terminals and opening socket connection between client and server) I have no problems. 这里发生的问题是,当我通过node.js在样本socekt.io客户端与此socket.io服务器之间连接时(仅运行两个终端并打开客户端与服务器之间的套接字连接),我没有问题。
But, when I am trying to inject this socket.io-client into my Ember.js application, precisely to ember-cli-mirage it redirects my client from given address : 但是,当我尝试将此socket.io-client注入到我的Ember.js应用程序中时,恰好是ember-cli-mirage,它从给定地址重定向了我的客户端:
( 'http: //localhost:8080') ('http:// localhost:8080')
to something like 像
http: //localhost:8080/socket.io/?EIO=3&transport=polling&..... http://localhost:8080/socket.io/?EIO=3&transport=polling&.....
also Mirage displays me an error that I cannot handle, even by setting up precise namespace, routing the wsClient.connect() method or calling this.passthrough() , before calling wsClient.connect() . Mirage还向我显示了一个我无法处理的错误,即使在调用wsClient.connect()之前,即使设置精确的名称空间,路由wsClient.connect()方法或调用this.passthrough() 也是如此 。
I also paste the the screenshot of error from inspect console in browser: 我还从浏览器的检查控制台粘贴了错误的屏幕截图:
Do you have any idea how to resolve this problem? 您知道如何解决此问题吗? Thank you in advance and I also hope that the topic is not duplicated.
在此先感谢您,我也希望不要重复该主题。
// server.js
var app = require('http').createServer(handler);
var io = require('socket.io')(app);
app.listen(8080);
function handler(req, res) {
res.writeHead(200);
res.end('default.index');
}
var rooms = {
'room1': [
],
'room2': [
]
};
io.on('connection', function(socket) {
console.log('client connected');
socket.on('join', function(roomName) {
rooms[roomName].push(socket.id);
socket.join(roomName);
});
socket.on('leave', function(roomName) {
var toRemove = rooms[roomName].indexOf(socket.id);
rooms[roomName].splice(toRemove, 1);
socket.leave('roomName');
});
socket.on('eNotification', function(data) {
console.log(data);
io.to(socket.id).emit('eNotificationCall', data);
io.to('room2').emit('eventNotification', data);
});
socket.on('gNotification', function(data) {
console.log(data);
io.to(socket.id).emit('gNotificationCall', data);
io.to('room1').emit('diagram1Notification', data);
});
socket.on('close', function() {
console.log('client disconnected');
});
});
//client.js
var wsClient = {
socket: null,
connect: function() {
this.socket = io.connect('http://localhost:8080');
this.socket.on('connect', function() {
console.log('mirage client connected!');
});
},
send: function(eventData, graphData) {
this.socket.emit('eNotification', eventData);
this.socket.emit('gNotification', graphData);
}
};
export default wsClient;
//config.js
import wsClient from './websockets/client';
export default function() {
wsClient.connect();
console.log(wsClient.socket);
var graphData = {X: "2", Y: "3"};
var eventData = {myDAta: 'myDAta', message: 'message'};
setInterval(function() {
wsClient.send(graphData, eventData);
}, 5000);
}
If you call this.passthrough()
with no args it only allows requests on the current domain to passthrough. 如果不带参数调用
this.passthrough()
,则仅允许当前域上的请求通过。 It looks like the websocket connection is on a different port, so try specifying it directly: 看来websocket连接在其他端口上,所以尝试直接指定它:
this.passthrough('http://localhost:8080/**');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.