@sealsystems/service-protocol
v2.1.0
Published
Determine protocol for connecting to service
Downloads
8
Readme
node-service-protocol
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
.
Installation
npm install @sealsystems/service-protocol
Usage
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
getProtocol(consul, hostname);
Returns the protocol for connection to a service on host hostname
.
isLocal
isLocal(consul, hostname);
Returns true
if hostname
is identical to the local host.