2012-01-02 137 views
1

我在端口3030上運行快速Web應用程序,但它通過http-proxy代理。該網站以這種方式正常工作,但socket.io不會連接。它收到的東西作爲我的控制檯顯示:NodeJS,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:: 

app.js

app.listen(3030) 

io = require('socket.io') 
socket = io.listen(app) 

socket.on('connection', function(client) { 
    console.log('new connection') 
}) 

chat.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代理代碼

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); 
+0

你應該粘貼您的HTTP代理配置 – 2012-01-02 10:01:17

+0

@xsace的代碼 - 我編輯的職位,包括HTTP代理腳本 – 2012-01-02 10:07:35

+0

我遇到了同樣的問題。你有沒有想過它? – 2012-11-01 05:40:18

回答

1

據我所知,節點HTTP代理不使用WebSockets與節點工作> 0.6.x,因爲一個錯誤的(這是幾個星期前)。他們說他們正在修復,所以他們可能還沒有解決這個問題。如果你不能這樣做,請嘗試bouncy

+2

對於任何想知道的人來說,alessioalex提到的問題應該已經在socket.io 0.8.0中解決了:https://github.com/nodejitsu/node -http-proxy/issues/161 – 2012-02-14 21:12:35

0

難道你不應該問地址127.0.0.1:3030上的socket.io?還連接到mydomain.com:3030。

如果我理解正確,你在3030端口上運行express應用程序,這樣你就需要在那裏連接到客戶端JS。

$(function() { 
    console.log('connecting to chat...') 
    var socket = io.connect('http://mydomain.com:3030'); 

    socket.on('connected',function(){ 
    console.log('connected') 
    }); 
}); 

我猜...

+0

他代理端口80,所以他的代碼是正確的。 – alessioalex 2012-01-02 13:07:52