]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
8c308c2b | 2 | |
f0f5567b C |
3 | const config = require('config') |
4 | const mongoose = require('mongoose') | |
8c308c2b | 5 | |
f0f5567b | 6 | const logger = require('../helpers/logger') |
8c308c2b | 7 | |
aaf61f38 C |
8 | // Bootstrap models |
9 | require('../models/video') | |
00057e85 C |
10 | // Request model needs Video model |
11 | require('../models/request') | |
aaf61f38 | 12 | |
f0f5567b C |
13 | const dbname = 'peertube' + config.get('database.suffix') |
14 | const host = config.get('database.host') | |
15 | const port = config.get('database.port') | |
8c308c2b | 16 | |
f0f5567b | 17 | const database = { |
9f10b292 C |
18 | connect: connect |
19 | } | |
c45f7f84 | 20 | |
9f10b292 C |
21 | function 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 | 34 | module.exports = database |