feat(config): set config default value on render index

This commit is contained in:
OldHawk
2017-12-29 13:56:08 +08:00
parent 71fa4692c2
commit 11635470bc
3 changed files with 28 additions and 7 deletions

View File

@@ -1,8 +1,6 @@
'use strict';
var validator = require('validator'),
path = require('path'),
moment = require('moment'),
var path = require('path'),
config = require(path.resolve('./config/config'));
/**
@@ -15,6 +13,8 @@ exports.renderIndex = function (req, res) {
req.user.addSignedIp(ip);
}
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
res.render('modules/core/server/views/index', {
user: JSON.stringify(safeUserObject),
sharedConfig: JSON.stringify(config.shared),
@@ -28,6 +28,8 @@ exports.renderIndex = function (req, res) {
exports.renderServerError = function (req, res) {
var safeUserObject = req.user || null;
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
res.status(500).render('modules/core/server/views/500', {
user: JSON.stringify(safeUserObject),
sharedConfig: JSON.stringify(config.shared),
@@ -43,6 +45,8 @@ exports.renderServerError = function (req, res) {
exports.renderNotFound = function (req, res) {
var safeUserObject = req.user || null;
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
res.status(404).format({
'text/html': function () {
res.render('modules/core/server/views/404', {
@@ -92,3 +96,20 @@ function getSafeMeanTorrentConfig(cfg) {
return cfg;
}
/**
* setMeanTorrentConfigDefaultValue
* @param cfg
*/
function setMeanTorrentConfigDefaultValue(req, res, cfg) {
var httpTransport = 'http://';
if (config.secure && config.secure.ssl === true) {
httpTransport = 'https://';
}
var baseUrl = req.app.get('domain') || httpTransport + req.headers.host;
cfg.app.domain = baseUrl;
if (!cfg.announce.url.startsWith('http')) {
cfg.announce.url = baseUrl + cfg.announce.url;
}
}