Support for arrays in url parameter
This commit is contained in:
parent
7d52f867a0
commit
3ca2c265da
|
@ -14,7 +14,7 @@ The code to create a new client looks like:
|
|||
|
||||
var ldap = require('ldapjs');
|
||||
var client = ldap.createClient({
|
||||
url: 'ldap://127.0.0.1:1389,127.0.0.2:1389'
|
||||
url: ['ldap://127.0.0.1:1389', 'ldap://127.0.0.2:1389']
|
||||
});
|
||||
|
||||
You can use `ldap://` or `ldaps://`; the latter would connect over SSL (note
|
||||
|
|
|
@ -112,10 +112,18 @@ function Client (options) {
|
|||
var self = this
|
||||
this.servers = []
|
||||
if (options.url) {
|
||||
var urls = options.url
|
||||
|
||||
if (typeof options.url === 'string') {
|
||||
var [, protocol, hosts, path] = options.url.match(/^([a-zA-Z]+:\/\/)([^/]*)(.*)/)
|
||||
|
||||
hosts.split(',').forEach((host) => {
|
||||
this.servers.push(url.parse(`${protocol}${host}${path}`))
|
||||
urls = hosts.split(',').map((host) => {
|
||||
return `${protocol}${host}${path}`
|
||||
})
|
||||
}
|
||||
|
||||
this.servers = urls.map((host) => {
|
||||
return url.parse(host)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ module.exports = {
|
|||
Client: Client,
|
||||
createClient: function createClient (options) {
|
||||
if (isObject(options) === false) throw TypeError('options (object) required')
|
||||
if (options.url && typeof options.url !== 'string') throw TypeError('options.url (string) required')
|
||||
if (options.url && typeof options.url !== 'string' && !Array.isArray(options.url)) throw TypeError('options.url (string|array) required')
|
||||
if (options.socketPath && typeof options.socketPath !== 'string') throw TypeError('options.socketPath must be a string')
|
||||
if ((options.url && options.socketPath) || !(options.url || options.socketPath)) throw TypeError('options.url ^ options.socketPath (String) required')
|
||||
if (!options.log) options.log = logger
|
||||
|
|
|
@ -341,9 +341,8 @@ tap.test('createClient', t => {
|
|||
})
|
||||
|
||||
t.test('url must be a string', async t => {
|
||||
const match = /options\.url \(string\) required/
|
||||
const match = /options\.url \(string\|array\) required/
|
||||
t.throws(() => ldap.createClient({ url: {} }), match)
|
||||
t.throws(() => ldap.createClient({ url: [] }), match)
|
||||
t.throws(() => ldap.createClient({ url: 42 }), match)
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue