2012-08-30 49 views
1

當使用http.createServer用Node.js的,我得到以下錯誤:Node.js的插座掛斷錯誤

events.js:48 
    throw arguments[1]; // Unhandled 'error' event 
       ^
Error: socket hang up 
at createHangUpError (http.js:1092:15) 
at Socket.onend (http.js:1155:27) 
at TCP.onread (net.js:349:26) 

簡單的代碼:

http.createServer(
    connect_cache({rules: [{regex: /.*/, ttl: 60000}]}), 
    function(b_request, b_response){ ..... } 
); 

那麼,是什麼錯誤呢?我該如何解決它?

謝謝!

回答

1

http.createServer()最多隻需要一個函數作爲其參數,然後將其設置爲事件的處理函數。 connect_cache()沒有正確的簽名作爲處理程序。據推測,它是作爲中間件編寫的,可在Connect或其他內容(如Express)上使用,但不能將Connect中間件直接傳遞給http.Server;您需要創建一個Connect對象,將中間件傳遞給它,然後將連接對象傳遞給http.createServer()