UNPKG

nsolid-statsd

Version:

a daemon that sends N|Solid metrics to statsd

24 lines (19 loc) 726 B
'use strict' // ensure endpoint starts w/ http:// or https:// module.exports = function normalizeEndpoint (endpoint, version) { if (endpoint == null) throw new Error('endpoint is required') if (typeof endpoint !== 'string') throw new Error('endpoint must be a string') if (endpoint === '') throw new Error('endpoint must not be empty string') if (version == null || version === 1) { version = 'v1' } if (version !== 'v1') { throw new Error('Only v1 of the API is currently supported') } // if doesn't match http:// or https://, use https:// endpoint = endpoint.trim() + '/api/' + version + '/' if (!endpoint.match(/^https?:\/\//)) { endpoint = 'https://' + endpoint } return endpoint }