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 mongoose = require('mongoose')
|
2015-06-09 10:41:40 -05:00
|
|
|
|
2016-08-19 14:34:51 -05:00
|
|
|
const constants = require('../initializers/constants')
|
2016-03-16 16:29:27 -05:00
|
|
|
const logger = require('../helpers/logger')
|
2015-06-09 10:41:40 -05:00
|
|
|
|
2016-06-24 10:42:51 -05:00
|
|
|
// Bootstrap models
|
2016-09-26 15:36:36 -05:00
|
|
|
require('../models/application')
|
2016-09-26 16:10:32 -05:00
|
|
|
require('../models/oauth-token')
|
2016-07-01 09:03:53 -05:00
|
|
|
require('../models/user')
|
|
|
|
require('../models/oauth-client')
|
2016-06-30 15:39:08 -05:00
|
|
|
require('../models/pods')
|
2016-06-24 10:42:51 -05:00
|
|
|
require('../models/video')
|
2016-06-28 13:10:32 -05:00
|
|
|
// Request model needs Video model
|
|
|
|
require('../models/request')
|
2016-06-24 10:42:51 -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 () {
|
2016-07-27 14:15:07 -05:00
|
|
|
mongoose.Promise = global.Promise
|
2016-08-19 14:34:51 -05:00
|
|
|
mongoose.connect('mongodb://' + constants.CONFIG.DATABASE.HOST + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME)
|
2016-02-07 04:23:23 -06:00
|
|
|
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
|