Restify不会听ipv6

时间:2014-09-08 20:04:14

标签: restify

使用来自restify的README的示例服务器,它启动并仅绑定到ipv4地址上的端口8080。有没有办法让它绑定到所有地址? Mac OS X。

$ node test.js
myapp listening at http://0.0.0.0:8080

$ netstat -an | grep 8080
tcp4       0      0  *.8080                 *.*                    LISTEN

它有点烦人,因为' localhost'首先尝试v6地址,一些客户端(例如:curl)不尝试其他地址。我必须记住要始终明确键入127.0.0.1。

$ curl http://localhost:8080/
curl: (7) Failed to connect to localhost port 8080: Connection refused

$ curl http://127.0.0.1:8080/
{"code":"ResourceNotFound","message":"/ does not exist"}

1 个答案:

答案 0 :(得分:2)

假设myapp listening at http://0.0.0.0:8080

中的消息test.js来自此类内容
app.listen(8080, function(err) {
  console.log("myapp listening at %s", app.url);
});

而是使用它:

app.listen(8080, '::', function(err) {
  console.log("myapp listening at %s", app.url);
});

这将使node.js同时侦听IPv4和IPv6接口。使用模块expressrestify进行了测试。