我在端口 3030 上运行一个快速 Web 应用程序,但它是通过http-proxy 代理的。该站点以这种方式运行良好,但 socket.io 将无法连接。当我的控制台显示时,它确实收到了一些东西:
debug - served static content /socket.io.js
debug - client authorized
info - handshake authorized 11319742841450363586
debug - setting request GET /socket.io/1/websocket/11319742841450363586
debug - set heartbeat interval for client 11319742841450363586
debug - client authorized for
debug - websocket writing 1::
应用程序.js
app.listen(3030)
io = require('socket.io')
socket = io.listen(app)
socket.on('connection', function(client) {
console.log('new connection')
})
聊天.js
$(function() {
console.log('connecting to chat...')
var socket = io.connect('http://mydomain.com:80')
socket.on('connected',function(){
console.log('connected')
})
})
但是,console.log 语句都不会显示在客户端或服务器端。我究竟做错了什么?
编辑 - 添加了 http-proxy 代码
var httpProxy = require('http-proxy')
, proxyTable = {
router: {
'lou.mydomain.com': '127.0.0.1:3030'
, 'foe.mydomain.com': '127.0.0.1:3000'
// and some others
}
}
, proxyServer = httpProxy.createServer(proxyTable);
proxyServer.listen(80);