fix(mongoose): unescaped character in username/password

This commit is contained in:
Luca Perret 2018-01-18 23:37:16 +01:00
parent 8b069da4e1
commit 4de3abe9e9
2 changed files with 10 additions and 2 deletions

View File

@ -46,7 +46,10 @@ module.exports = function (strapi) {
if (_.isEmpty(username) || _.isEmpty(password)) {
instance.connect(`mongodb://${host}:${port}/${database}`);
} else {
instance.connect(`mongodb://${username}:${password}@${host}:${port}/${database}`);
instance.connect(`mongodb://${host}:${port}/${database}`, {
user: username,
pass: password
});
}
// Handle error

View File

@ -10,7 +10,12 @@ const logger = require('strapi-utils').logger;
module.exports = (scope, success, error) => {
const Mongoose = require(path.resolve(`${scope.rootPath}/node_modules/mongoose`));
Mongoose.connect(`mongodb://${ (scope.database.settings.username && scope.database.settings.password) ? `${scope.database.settings.username}:${scope.database.settings.password}@` : '' }${scope.database.settings.host}:${scope.database.settings.port}/${scope.database.settings.database}`, function (err) {
const connectOptions = {}
if (scope.database.settings.username && scope.database.settings.password) {
connectOptions.user = scope.database.settings.username
connectOptions.pass = scope.database.settings.password
}
Mongoose.connect(`mongodb://${scope.database.settings.host}:${scope.database.settings.port}/${scope.database.settings.database}`, connectOptions, function (err) {
if (err) {
logger.warn('Database connection has failed! Make sure your database is running.');
return error();