From 959a658aaee1590a00429d57b20f5aee91a4e70d Mon Sep 17 00:00:00 2001 From: OldHawk Date: Sun, 7 Jan 2018 10:28:21 +0800 Subject: [PATCH] feat(core): add configure item to set setDefaultValueOnIndex set app.domain and announce.url on renderer index if false, app.domain and announce.url used these config settings value if true, app.domain and announce.url used req.app.get('domain') || req.headers.host if web server used proxyPass setting, this should set to false --- config/env/default.js | 2 +- config/env/torrents.js | 9 +++++++-- .../controllers/core.server.controller.js | 17 ++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/config/env/default.js b/config/env/default.js index 9ca05b9a..bee0707e 100644 --- a/config/env/default.js +++ b/config/env/default.js @@ -14,7 +14,7 @@ module.exports = { host: process.env.HOST || '0.0.0.0', // DOMAIN config should be set to the fully qualified application accessible // URL. For example: https://www.myapp.com (including port if required). - domain: process.env.DOMAIN || 'chd.im:3000', + domain: process.env.DOMAIN || 'chd.im', // Session Cookie settings sessionCookie: { // session expiration is set by default to 24 hours diff --git a/config/env/torrents.js b/config/env/torrents.js index efa96b7e..b9fd4767 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -13,13 +13,18 @@ module.exports = { * @cronTimeZone: timezone of cron * @showDebugLog: if true, will console.log all debug info at server side and client side. when your site is prod env, please change this * value to false, then console.log info is not output + * @setDefaultValueOnIndex: set app.domain and announce.url on renderer index + * if false, app.domain and announce.url used these config settings value + * if true, app.domain and announce.url used req.app.get('domain') || req.headers.host + * if web server used proxyPass setting, this should set to false */ app: { name: 'CHD.im', - domain: 'http://chd.im:3000', + domain: 'http://chd.im', showDemoWarningPopup: true, cronTimeZone: 'Asia/Shanghai', - showDebugLog: true + showDebugLog: true, + setDefaultValueOnIndex: true }, /** diff --git a/modules/core/server/controllers/core.server.controller.js b/modules/core/server/controllers/core.server.controller.js index 13cda8bd..d83eb49c 100644 --- a/modules/core/server/controllers/core.server.controller.js +++ b/modules/core/server/controllers/core.server.controller.js @@ -105,17 +105,20 @@ function getSafeMeanTorrentConfig(cfg) { * @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; + if (config.meanTorrentConfig.app.setDefaultValueOnIndex) { + 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; + } - cfg.app.domain = baseUrl; if (!cfg.announce.abs) { cfg.announce.abs = cfg.announce.url; } - cfg.announce.url = baseUrl + cfg.announce.abs; + cfg.announce.url = cfg.app.domain + cfg.announce.abs; return cfg; }