2012-08-30 47 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()