Ho scritto proxy http in node.js in esecuzione sulla porta 80. Tutto ciò di cui ho bisogno è di reindirizzare il traffico socket.io alla porta 9090 e il traffico http standard ad Apache su 8080. Questo è il mio codice proxy:node.js: proxy websockets ad altra porta
httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
if (req.url.match(/socket.io/)) {
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9090
});
} else {
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 8080
});
}
}).listen(80);
Tutto funziona, ma io.socket torna al xhr-polling.
http://localhost/client.htm - falls back to xhr-polling
file:///C:/.../client9090.htm - still uses websocket
socket.io applicazione è in esecuzione sulla porta 9090, Client.htm collega a 80 e client9090.htm si collega direttamente al 9090.
Sembra un nodo-http-proxy rende app socket.io lavorare in modalità xhr-polling. Cliente è Chrome V.25
codice socket.io app
var io = require('socket.io').listen(9090);
io.on('connection', function (socket) {
socket.on('hi!', function (data) {
console.log(data);
socket.emit('news');
});
socket.on('ahoj', function (data) {
console.log(data);
});
});
codice Client.htm
<script src="http://localhost/socket.io/socket.io.js"></script>
<script>
var chat = io.connect('http://localhost')
chat.on('connect', function() {
chat.emit('hi!');
});
chat.on('news', function() {
chat.emit('ahoj',{a:1,b:2});
});
</script>
client9090.htm è lo stesso ma localhost è sostituito dal localhost: 9090
Come ho detto, everythig funziona bene, solo il problema è che il nodo-http-proxy fa cadere da websockets a xhr-polling. Qualcuno può aiutare?