Determine protocol for connecting to a service using consul for resolving local hostname if necessary.
The environment variable TLS_UNPROTECTED
is used with the folowing values:
-
none
No unprotected connections are used andgetProtocol
always returnshttps
-
world
All connections are unprotected andgetProtocol
always returnshttp
-
loopback
(default) Connections to localhost are unprotected andgetProtocol
returnshttp
, external connections are protected andgetProtocol
returnhttps
.
npm install @sealsystems/service-protocol
const serviceProtocol = require('@sealsystems/service-protocol');
const consul = ... // get consul from somewhere
const protocol = serviceProtocol.getProtocol(consul, 'localhost');
// --> 'http'
const isLocal = serviceProtocol.isLocal(consul, 'localhost');
// --> true
getProtocol(consul, hostname);
Returns the protocol for connection to a service on host hostname
.
isLocal(consul, hostname);
Returns true
if hostname
is identical to the local host.