1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-13 22:15:57 +00:00

moving the db setup out

This commit is contained in:
Scott Tolksdorf
2017-01-01 12:42:19 -08:00
parent 25e0a1607a
commit a0bc4fddf8
3 changed files with 25 additions and 8 deletions

View File

@@ -14,13 +14,7 @@ const config = require('nconf')
.file('defaults', { file: 'config/default.json' });
//DB
require('mongoose')
.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/naturalcrit')
.connection.on('error', () => {
console.error('Error : Could not connect to a Mongo Database.');
console.error(' If you are running locally, make sure mongodb.exe is running.');
});
require('./server/db.js').connect();
//Middleware
const mw = require('./server/middleware.js');

18
server/db.js Normal file
View File

@@ -0,0 +1,18 @@
module.exports = {
connect : ()=>{
return new Promise((resolve, reject)=>{
require('mongoose')
.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/homebrewery',
(err) => {
if(err){
console.log('Error : Could not connect to a Mongo Database.');
console.log(' If you are running locally, make sure mongodb.exe is running.');
return reject();
}
return resolve();
}
);
});
}
}

View File

@@ -12,11 +12,16 @@ describe('BrewDB', () => {
return BrewDB.create({
text : "Brew Text"
}).then((brew) => {
console.log('running?');
should.exist(brew);
brew.should.have.property('editId').that.is.a('string');
brew.should.have.property('shareId').that.is.a('string');
brew.should.have.property('text').that.is.a('string');
});
done();
})
.catch(()=>{
console.log('yo');
})
});
});