2016-02-07 05:23:23 -05:00
|
|
|
'use strict'
|
2015-06-09 11:41:40 -04:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
var config = require('config')
|
|
|
|
var mongoose = require('mongoose')
|
2015-06-09 11:41:40 -04:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
var logger = require('../helpers/logger')
|
2015-06-09 11:41:40 -04:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
var dbname = 'peertube' + config.get('database.suffix')
|
|
|
|
var host = config.get('database.host')
|
|
|
|
var port = config.get('database.port')
|
2015-06-09 11:41:40 -04:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
var database = {
|
|
|
|
connect: connect
|
|
|
|
}
|
2016-01-31 05:23:52 -05:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
function connect () {
|
|
|
|
mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
|
|
|
|
mongoose.connection.on('error', function () {
|
2016-02-07 06:01:40 -05:00
|
|
|
throw new Error('Mongodb connection error.')
|
2016-02-07 05:23:23 -05:00
|
|
|
})
|
2016-01-31 05:23:52 -05:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
mongoose.connection.on('open', function () {
|
|
|
|
logger.info('Connected to mongodb.')
|
|
|
|
})
|
|
|
|
}
|
2016-01-31 05:23:52 -05:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
2015-06-09 11:41:40 -04:00
|
|
|
|
2016-02-07 05:23:23 -05:00
|
|
|
module.exports = database
|