2016-02-07 11:23:23 +01:00
|
|
|
'use strict'
|
2015-06-09 17:41:40 +02:00
|
|
|
|
2016-03-16 22:29:27 +01:00
|
|
|
const mongoose = require('mongoose')
|
2015-06-09 17:41:40 +02:00
|
|
|
|
2016-08-19 21:34:51 +02:00
|
|
|
const constants = require('../initializers/constants')
|
2016-03-16 22:29:27 +01:00
|
|
|
const logger = require('../helpers/logger')
|
2015-06-09 17:41:40 +02:00
|
|
|
|
2016-06-24 17:42:51 +02:00
|
|
|
// Bootstrap models
|
2016-09-26 22:36:36 +02:00
|
|
|
require('../models/application')
|
2016-09-26 23:10:32 +02:00
|
|
|
require('../models/oauth-token')
|
2016-07-01 16:03:53 +02:00
|
|
|
require('../models/user')
|
|
|
|
require('../models/oauth-client')
|
2016-06-24 17:42:51 +02:00
|
|
|
require('../models/video')
|
2016-06-28 20:10:32 +02:00
|
|
|
// Request model needs Video model
|
2016-10-21 11:20:45 +02:00
|
|
|
require('../models/pods')
|
|
|
|
// Request model needs Pod model
|
2016-06-28 20:10:32 +02:00
|
|
|
require('../models/request')
|
2016-06-24 17:42:51 +02:00
|
|
|
|
2016-03-16 22:29:27 +01:00
|
|
|
const database = {
|
2016-02-07 11:23:23 +01:00
|
|
|
connect: connect
|
|
|
|
}
|
2016-01-31 11:23:52 +01:00
|
|
|
|
2016-02-07 11:23:23 +01:00
|
|
|
function connect () {
|
2016-07-27 21:15:07 +02:00
|
|
|
mongoose.Promise = global.Promise
|
2016-10-23 19:41:17 +02:00
|
|
|
mongoose.connect('mongodb://' + constants.CONFIG.DATABASE.HOSTNAME + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME)
|
2016-02-07 11:23:23 +01:00
|
|
|
mongoose.connection.on('error', function () {
|
2016-02-07 12:01:40 +01:00
|
|
|
throw new Error('Mongodb connection error.')
|
2016-02-07 11:23:23 +01:00
|
|
|
})
|
2016-01-31 11:23:52 +01:00
|
|
|
|
2016-02-07 11:23:23 +01:00
|
|
|
mongoose.connection.on('open', function () {
|
|
|
|
logger.info('Connected to mongodb.')
|
|
|
|
})
|
|
|
|
}
|
2016-01-31 11:23:52 +01:00
|
|
|
|
2016-02-07 11:23:23 +01:00
|
|
|
// ---------------------------------------------------------------------------
|
2015-06-09 17:41:40 +02:00
|
|
|
|
2016-02-07 11:23:23 +01:00
|
|
|
module.exports = database
|