49 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
// Node.js core.
const execSync = require('child_process').execSync;
const path = require('path');
// Logger.
const logger = require('strapi-utils').logger;
module.exports = (scope, success, error) => {
const Mongoose = require(path.resolve(`${scope.tmpPath}/node_modules/mongoose`));
2018-02-02 18:27:03 +01:00
const { username, password } = scope.database.settings;
const { authenticationDatabase, ssl } = scope.database.options;
const connectOptions = {};
if (username) {
connectOptions.user = username;
if (password) {
connectOptions.pass = password;
}
}
2018-03-08 15:51:03 +01:00
if (authenticationDatabase) {
connectOptions.authSource = authenticationDatabase;
}
connectOptions.ssl = ssl ? true : false;
Mongoose.connect(`mongodb://${scope.database.settings.host}:${scope.database.settings.port}/${scope.database.settings.database}`, connectOptions, function (err) {
if (err) {
2018-01-10 18:08:43 +01:00
logger.warn('Database connection has failed! Make sure your database is running.');
return error();
}
2018-01-10 18:08:43 +01:00
logger.info('The app has been connected to the database successfully!');
Mongoose.connection.close();
2018-03-18 13:29:49 +01:00
execSync(`rm -r "${scope.tmpPath}"`);
logger.info('Copying the dashboard...');
success();
});
};