]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/database.js
Do not generate a random password for test env
[github/Chocobozzz/PeerTube.git] / server / initializers / database.js
CommitLineData
9f10b292 1'use strict'
8c308c2b 2
f0f5567b
C
3const config = require('config')
4const mongoose = require('mongoose')
8c308c2b 5
f0f5567b 6const logger = require('../helpers/logger')
8c308c2b 7
aaf61f38
C
8// Bootstrap models
9require('../models/video')
00057e85
C
10// Request model needs Video model
11require('../models/request')
aaf61f38 12
f0f5567b
C
13const dbname = 'peertube' + config.get('database.suffix')
14const host = config.get('database.host')
15const port = config.get('database.port')
8c308c2b 16
f0f5567b 17const database = {
9f10b292
C
18 connect: connect
19}
c45f7f84 20
9f10b292
C
21function connect () {
22 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
23 mongoose.connection.on('error', function () {
ac2f99eb 24 throw new Error('Mongodb connection error.')
9f10b292 25 })
c45f7f84 26
9f10b292
C
27 mongoose.connection.on('open', function () {
28 logger.info('Connected to mongodb.')
29 })
30}
c45f7f84 31
9f10b292 32// ---------------------------------------------------------------------------
8c308c2b 33
9f10b292 34module.exports = database