]>
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 | |
f0f5567b C |
8 | const dbname = 'peertube' + config.get('database.suffix') |
9 | const host = config.get('database.host') | |
10 | const port = config.get('database.port') | |
8c308c2b | 11 | |
f0f5567b | 12 | const database = { |
9f10b292 C |
13 | connect: connect |
14 | } | |
c45f7f84 | 15 | |
9f10b292 C |
16 | function connect () { |
17 | mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) | |
18 | mongoose.connection.on('error', function () { | |
ac2f99eb | 19 | throw new Error('Mongodb connection error.') |
9f10b292 | 20 | }) |
c45f7f84 | 21 | |
9f10b292 C |
22 | mongoose.connection.on('open', function () { |
23 | logger.info('Connected to mongodb.') | |
24 | }) | |
25 | } | |
c45f7f84 | 26 | |
9f10b292 | 27 | // --------------------------------------------------------------------------- |
8c308c2b | 28 | |
9f10b292 | 29 | module.exports = database |