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