2015-06-09 10:41:40 -05:00
|
|
|
;(function () {
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
var config = require('config')
|
|
|
|
var mongoose = require('mongoose')
|
|
|
|
|
2016-01-30 10:05:22 -06:00
|
|
|
var logger = require('../helpers/logger')
|
2015-06-09 10:41:40 -05:00
|
|
|
|
2015-10-29 17:29:12 -05:00
|
|
|
var dbname = 'peertube' + config.get('database.suffix')
|
2015-06-09 10:41:40 -05:00
|
|
|
var host = config.get('database.host')
|
|
|
|
var port = config.get('database.port')
|
|
|
|
|
2016-02-04 14:10:33 -06:00
|
|
|
var database = {
|
|
|
|
connect: connect
|
|
|
|
}
|
2016-01-31 04:23:52 -06:00
|
|
|
|
2016-02-04 14:10:33 -06:00
|
|
|
function connect () {
|
|
|
|
mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
|
|
|
|
mongoose.connection.on('error', function () {
|
|
|
|
logger.error('Mongodb connection error.')
|
|
|
|
process.exit(0)
|
|
|
|
})
|
2016-01-31 04:23:52 -06:00
|
|
|
|
2016-02-04 14:10:33 -06:00
|
|
|
mongoose.connection.on('open', function () {
|
|
|
|
logger.info('Connected to mongodb.')
|
|
|
|
})
|
2016-01-31 04:23:52 -06:00
|
|
|
}
|
|
|
|
|
2016-02-04 14:10:33 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
2015-06-09 10:41:40 -05:00
|
|
|
|
2016-02-04 14:10:33 -06:00
|
|
|
module.exports = database
|
2015-06-09 10:41:40 -05:00
|
|
|
})()
|