- updated copyright - several tempalate changes for the docs - added a config for grunt-contrib-watch - updated nock commit number - fixed the coverage script - removed the export_docs script - added error message for legacy "es" users who don't have a version locked and have not upgraded - host will now add auth to urls created with `#makeUrl()` - Log class no longer looks for `config.loggers` - The log class now properly escapes single quotes in trace logs - Removed compiled yaml_tests.js from the repo - Yaml suite will only log error and warning messages unless the VERBOSE env var is set - createDefer is now a global setting, changed by modifying Transport.createDefer fubction - wrote tests for Content-Type checking - callbacks will now return the body and status of the request (if the request has completed) when an error occurs - Stdio logger now adds "Elasticsearch " to the front of log messages to distinguish it from other output to stdout.
82 lines
1.8 KiB
JavaScript
82 lines
1.8 KiB
JavaScript
if (process.browser) {
|
|
/* jshint browser: true */
|
|
var es = window.elasticsearch;
|
|
} else {
|
|
var es = require('../../../src/elasticsearch');
|
|
}
|
|
var argv = require('./argv');
|
|
var server = require('./server');
|
|
// var path = require('path');
|
|
// var fs = require('fs');
|
|
var _ = require('../../../src/lib/utils');
|
|
|
|
// current client
|
|
var client = null;
|
|
|
|
// when set to a boolean, hold the test of a ping
|
|
var externalExists;
|
|
|
|
// a reference to a personal instance of ES Server
|
|
var esServer = null;
|
|
|
|
module.exports = {
|
|
create: function create(cb) {
|
|
if (argv.createServer || externalExists === false) {
|
|
if (!esServer) {
|
|
server.start(function (err, _server) {
|
|
esServer = _server;
|
|
if (err) {
|
|
done(err);
|
|
} else {
|
|
doCreateClient(done);
|
|
}
|
|
});
|
|
} else {
|
|
doCreateClient(done);
|
|
}
|
|
} else if (externalExists === void 0) {
|
|
doCreateClient(function () {
|
|
client.ping(function (err) {
|
|
if (err instanceof es.errors.ConnectionFault) {
|
|
externalExists = false;
|
|
create(done);
|
|
} else {
|
|
done(err);
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
doCreateClient(done);
|
|
}
|
|
|
|
function done(err) {
|
|
cb(err, client);
|
|
}
|
|
|
|
function doCreateClient(cb) {
|
|
// close existing client
|
|
if (client) {
|
|
client.close();
|
|
}
|
|
|
|
client = new es.Client({
|
|
hosts: [
|
|
{
|
|
host: esServer ? esServer.__hostname : argv.host,
|
|
port: esServer ? esServer.__port : argv.port
|
|
}
|
|
],
|
|
log: {
|
|
type: process.browser ? 'console' : 'stdio',
|
|
level: process.env.VERBOSE ? 'trace' : 'warning'
|
|
}
|
|
});
|
|
|
|
_.nextTick(cb);
|
|
}
|
|
},
|
|
get: function () {
|
|
return client;
|
|
}
|
|
};
|