Please, check the full documentation below.
Table of Contents
Using npm:
$ npm install --save consul-service-registrator
Using yarn:
$ yarn add consul-service-registrator
Lib provides 3 classes:
IpAddressDetector
ServiceObserver
Registrator
Class has a method getLanAndWanFromConsul
that return Promise.
Method fetches from consul a response of /v1/agent/self
and
- if both
Config.AdvertiseAddr
andConfig.AdvertiseAddrWan
are present returns them back asresult.lanIp
andresult.wanIp
correspondingly; - if both
DebugConfig.AdvertiseAddrLAN
andDebugConfig.AdvertiseAddrWAN
are present returns them back asresult.lanIp
andresult.wanIp
correspondingly.
Note.
Config
shows the explicitly defined configuration.DebugConfig
shows how Consul interpreted and applied the configuration in practice. TaggedAddresses show explicitly set values that are delivered through gossip
const {IpAddressDetector} = require('consul-service-registrator');
const consulConfig = {
host: '127.0.0.1',
port: 8500
};
const ipAddressDetector = new IpAddressDetector(consulConfig);
ipAddressDetector.getLanAndWanFromConsul().then(result => {
console.log(result);
}).catch(err => {
console.log(err);
})
Check the
example
folder and you may find use cases.