mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-07 19:26:09 +02:00
feat(config): set config default value on render index
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user