考慮以下代碼用於其餘API節點服務器。如何獲取Restify服務器的確切IP地址進行監聽?
var restify = require('restify');
var server = restify.createServer();
server.get('/echo/:name', function (req, res, next) {
res.send({name: req.params.name});
next();
});
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
運行了該服務器節點:
$ node echo.js
restify listening at http://0.0.0.0:8080
它顯示0.0.0.0
這是不對的。
任何人都可以如何控制檯登錄服務器的確切IP時,它打開?
感謝
更新: 上執行下面的代碼我得到下面提到的輸出,這又是製造困難,這IP選?
rest_server.listen(config.appPort, function() {
var adrs = require('os').networkInterfaces();
console.log(adrs);
console.log('%s listening at %s', rest_server.name, rest_server.url);
});
輸出:
{ 'Local Area Connection': [ { address: '192.168.3.60', family: 'IPv4', internal
: false } ],
'Loopback Pseudo-Interface 1':
[ { address: '::1', family: 'IPv6', internal: true },
{ address: '127.0.0.1', family: 'IPv4', internal: true } ],
'isatap.TEST.ORG':
[ { address: 'fe80::5efe:c0a8:33c',
family: 'IPv6',
internal: false } ] }
restify listening at http://0.0.0.0:8080
在這種情況下,你應該選擇'192.168.3.60',因爲它不是內部*和* IPv4的。 – robertklep