1
0
Fork 0
peertube/server/initializers/database.js

36 lines
933 B
JavaScript
Raw Normal View History

'use strict'
2015-06-09 11:41:40 -04:00
2016-03-16 17:29:27 -04:00
const mongoose = require('mongoose')
2015-06-09 11:41:40 -04:00
2016-08-19 15:34:51 -04:00
const constants = require('../initializers/constants')
2016-03-16 17:29:27 -04:00
const logger = require('../helpers/logger')
2015-06-09 11:41:40 -04:00
// Bootstrap models
require('../models/user')
require('../models/oauth-client')
require('../models/oauth-token')
require('../models/pods')
require('../models/video')
// Request model needs Video model
require('../models/request')
2016-03-16 17:29:27 -04:00
const database = {
connect: connect
}
2016-01-31 05:23:52 -05:00
function connect () {
mongoose.Promise = global.Promise
2016-08-19 15:34:51 -04:00
mongoose.connect('mongodb://' + constants.CONFIG.DATABASE.HOST + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME)
mongoose.connection.on('error', function () {
throw new Error('Mongodb connection error.')
})
2016-01-31 05:23:52 -05:00
mongoose.connection.on('open', function () {
logger.info('Connected to mongodb.')
})
}
2016-01-31 05:23:52 -05:00
// ---------------------------------------------------------------------------
2015-06-09 11:41:40 -04:00
module.exports = database