Merge branch 'master' into ux/ctm-list-view

This commit is contained in:
Jim LAURIE 2018-08-23 17:24:57 +02:00 committed by GitHub
commit 1051c1cfbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -141,11 +141,18 @@ module.exports = (scope, cb) => {
message: 'Host:',
default: _.get(scope.database, 'host', '127.0.0.1')
},
{
when: !hasDatabaseConfig && scope.client.database === 'mongo',
type: 'boolean',
name: 'srv',
message: '+srv connection::',
default: _.get(scope.database, 'srv', false)
},
{
when: !hasDatabaseConfig,
type: 'input',
name: 'port',
message: 'Port:',
message: 'Port(It will be ignored if you enable +srv):',
default: (answers) => { // eslint-disable-line no-unused-vars
if (_.get(scope.database, 'port')) {
return scope.database.port;
@ -196,6 +203,7 @@ module.exports = (scope, cb) => {
}
scope.database.settings.host = answers.host;
scope.database.settings.srv = answers.srv;
scope.database.settings.port = answers.port;
scope.database.settings.database = answers.database;
scope.database.settings.username = answers.username;
@ -251,6 +259,7 @@ module.exports = (scope, cb) => {
require(path.join(`${scope.tmpPath}`, '/node_modules/', `${scope.client.connector}/lib/utils/connectivity.js`))(scope, cb.success, connectionValidation);
} catch(err) {
shell.rm('-r', scope.tmpPath);
console.log(err)
cb.success();
}
});

View File

@ -7,7 +7,7 @@ const path = require('path');
module.exports = (scope, success, error) => {
const Mongoose = require(path.resolve(`${scope.tmpPath}/node_modules/mongoose`));
const { username, password } = scope.database.settings;
const { username, password, srv } = scope.database.settings;
const { authenticationDatabase, ssl } = scope.database.options;
const connectOptions = {};
@ -26,8 +26,9 @@ module.exports = (scope, success, error) => {
connectOptions.ssl = ssl ? true : false;
connectOptions.useNewUrlParser = true;
connectOptions.dbName = scope.database.settings.database;
Mongoose.connect(`mongodb://${scope.database.settings.host}:${scope.database.settings.port}/${scope.database.settings.database}`, connectOptions, function (err) {
Mongoose.connect(`mongodb${srv ? "+srv" : ""}://${scope.database.settings.host}:${!srv ? ":" + scope.database.settings.port : ""}/`, connectOptions, function (err) {
if (err) {
console.log('⚠️ Database connection has failed! Make sure your database is running.');
return error();