Skip to content
This repository has been archived by the owner on Jun 14, 2019. It is now read-only.

Commit

Permalink
Setup neDB config
Browse files Browse the repository at this point in the history
  • Loading branch information
eljenso committed Dec 3, 2015
1 parent 81537d8 commit 813efd5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
5 changes: 4 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ var config = {
adress: 'ws://127.0.0.1:6680/mopidy/ws/',
defaultPlaylist: 'Party 2015'
},
db: 'mongodb://localhost/livid',
db: {
queuePath: 'queue.db',
historyPath: 'history.db'
},
user: {
voteDelay: 60 * 1000
}
Expand Down
38 changes: 22 additions & 16 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
var Hapi = require('hapi'),
server = new Hapi.Server(),
mongoose = require('mongoose'),
nedb = require('nedb'),
glob = require('glob');

// Load configfile
var config = require('./config.js');

server.connection({ port: config.main.port });

mongoose.connect(config.db);
var db = mongoose.connection;
db.on('error', function () {
throw new Error('unable to connect to database at ' + config.db);
});
// Load database
var db = {};
db.queue = new nedb({ filename: config.db.queuePath, autoload: true });
db.history = new nedb({ filename: config.db.historyPath, autoload: true });


var models = glob.sync('./models/*.js');
models.forEach(function (model) {
require(model);
});

if (process.env.ENV !== 'prod') {
mongoose.connection.collections['queuetracks'].drop( function(err) {
console.log('old queue tracks dropped');
});
}
// var models = glob.sync('./models/*.js');
// models.forEach(function (model) {
// require(model);
// });

// if (process.env.ENV !== 'prod') {
// mongoose.connection.collections['queuetracks'].drop( function(err) {
// console.log('old queue tracks dropped');
// });
// }

/*
var socket = require('./modules/socketLogic.js');
socket.init(server.listener);
var mopidy = require('./modules/mopidyCom.js');
mopidy.init();
*/

server.views({
engines: {
Expand Down Expand Up @@ -75,6 +78,9 @@ server.route({
});


// Configure hapi server
server.connection({ port: config.main.port });

server.start(function () {
console.log('Server running at:', server.info.uri);
});

0 comments on commit 813efd5

Please sign in to comment.