diff options
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.js | 27 | ||||
-rw-r--r-- | server/initializers/database.js | 8 |
2 files changed, 29 insertions, 6 deletions
diff --git a/server/initializers/constants.js b/server/initializers/constants.js index cd2e0cfb9..ce9f8ad6c 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js | |||
@@ -1,8 +1,34 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const config = require('config') | ||
4 | const path = require('path') | ||
5 | |||
3 | // API version of our pod | 6 | // API version of our pod |
4 | const API_VERSION = 'v1' | 7 | const API_VERSION = 'v1' |
5 | 8 | ||
9 | const CONFIG = { | ||
10 | DATABASE: { | ||
11 | DBNAME: 'peertube' + config.get('database.suffix'), | ||
12 | HOST: config.get('database.host'), | ||
13 | PORT: config.get('database.port') | ||
14 | }, | ||
15 | ELECTRON: { | ||
16 | DEBUG: config.get('electron.debug') | ||
17 | }, | ||
18 | STORAGE: { | ||
19 | CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')), | ||
20 | LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')), | ||
21 | UPLOAD_DIR: path.join(__dirname, '..', '..', config.get('storage.uploads')), | ||
22 | THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')) | ||
23 | }, | ||
24 | WEBSERVER: { | ||
25 | SCHEME: config.get('webserver.https') === true ? 'https' : 'http', | ||
26 | HOST: config.get('webserver.host'), | ||
27 | PORT: config.get('webserver.port') | ||
28 | } | ||
29 | } | ||
30 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT | ||
31 | |||
6 | const CONSTRAINTS_FIELDS = { | 32 | const CONSTRAINTS_FIELDS = { |
7 | USERS: { | 33 | USERS: { |
8 | USERNAME: { min: 3, max: 20 }, // Length | 34 | USERNAME: { min: 3, max: 20 }, // Length |
@@ -89,6 +115,7 @@ if (isTestInstance() === true) { | |||
89 | 115 | ||
90 | module.exports = { | 116 | module.exports = { |
91 | API_VERSION: API_VERSION, | 117 | API_VERSION: API_VERSION, |
118 | CONFIG: CONFIG, | ||
92 | CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, | 119 | CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, |
93 | FRIEND_SCORE: FRIEND_SCORE, | 120 | FRIEND_SCORE: FRIEND_SCORE, |
94 | INTERVAL: INTERVAL, | 121 | INTERVAL: INTERVAL, |
diff --git a/server/initializers/database.js b/server/initializers/database.js index 8626895ee..20dcc056e 100644 --- a/server/initializers/database.js +++ b/server/initializers/database.js | |||
@@ -1,8 +1,8 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const config = require('config') | ||
4 | const mongoose = require('mongoose') | 3 | const mongoose = require('mongoose') |
5 | 4 | ||
5 | const constants = require('../initializers/constants') | ||
6 | const logger = require('../helpers/logger') | 6 | const logger = require('../helpers/logger') |
7 | 7 | ||
8 | // Bootstrap models | 8 | // Bootstrap models |
@@ -14,17 +14,13 @@ require('../models/video') | |||
14 | // Request model needs Video model | 14 | // Request model needs Video model |
15 | require('../models/request') | 15 | require('../models/request') |
16 | 16 | ||
17 | const dbname = 'peertube' + config.get('database.suffix') | ||
18 | const host = config.get('database.host') | ||
19 | const port = config.get('database.port') | ||
20 | |||
21 | const database = { | 17 | const database = { |
22 | connect: connect | 18 | connect: connect |
23 | } | 19 | } |
24 | 20 | ||
25 | function connect () { | 21 | function connect () { |
26 | mongoose.Promise = global.Promise | 22 | mongoose.Promise = global.Promise |
27 | mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) | 23 | mongoose.connect('mongodb://' + constants.CONFIG.DATABASE.HOST + ':' + constants.CONFIG.DATABASE.PORT + '/' + constants.CONFIG.DATABASE.DBNAME) |
28 | mongoose.connection.on('error', function () { | 24 | mongoose.connection.on('error', function () { |
29 | throw new Error('Mongodb connection error.') | 25 | throw new Error('Mongodb connection error.') |
30 | }) | 26 | }) |