42 lines
1.0 KiB
JavaScript
Raw Normal View History

'use strict';
// Node.js core.
const execSync = require('child_process').execSync;
const path = require('path');
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-06-22 15:25:15 +02:00
console.log('⚠️ Database connection has failed! Make sure your database is running.');
return error();
}
Mongoose.connection.close();
2018-03-18 13:29:49 +01:00
execSync(`rm -r "${scope.tmpPath}"`);
success();
});
};