Skip to content

a promise convering SRV URI into a regular one, see RFC 2782

License

Notifications You must be signed in to change notification settings

jochen-schweizer/srv-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SRV Promise

A set of functions providing promisified interface to resolve SRV domain names as an object, array of objects or in-place inside of a URI.

The module is intended for microservices infrastrucutrs managed with mesos, consul or other tools providing service registry through SRV DNS interface.

The goal is to have the same application bootstrap code workig with a fixed host (e.g. in develpoment environment) and with SRV domains (e.g. in production).

The SRV is recognized by one of the coditions (or both):

  • if protocol has +srv component, e.g. mongodb+srv://weird-service.consul/myDb similar to http+srv draft
  • if domain name starts with _ as described in RFC 2782

Example:

const srvPromise = require('srv-proxy');
const mongoose = require('mongoose');

const config = {mongoUri: 'mongodb+srv://_mongo._tcp.example.com'};

srvPromise
  .proxyUri(config.mongoUri)
  .then(uri => {
    console.log('uri resolved as: ' + uri);
    mongoose.connect(uri);    
  });

mongoose.connection.on('open', () => console.log('connected'));

API

proxyUri(uri, options)

takes URI, resolves it if it has an SRV domain, otherwise just passes through. Returns a promise resolved to the new

  • uri: string, any URI with a domain name, and optionally containing protocol, credentials, path or query
  • options: object

License

MIT

About

a promise convering SRV URI into a regular one, see RFC 2782

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published