mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-03 18:51:09 +01:00
feat(config): adds a generic DOMAIN configuration environment (#1469)
Generic DOMAI configuration environment variable, useful for setting links to an app in reset email templates, and other cases. Fixes #871 and #847
This commit is contained in:
@@ -68,6 +68,14 @@ var validateEnvironmentVariable = function () {
|
||||
console.log(chalk.white(''));
|
||||
};
|
||||
|
||||
/** Validate config.domain is set
|
||||
*/
|
||||
var validateDomainIsSet = function (config) {
|
||||
if (!config.app.domain) {
|
||||
console.log(chalk.red('+ Important warning: config.domain is empty. It should be set to the fully qualified domain of the app.'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate Secure=true parameter can actually be turned on
|
||||
* because it requires certs and key files to be available
|
||||
@@ -204,6 +212,9 @@ var initGlobalConfig = function () {
|
||||
// Validate session secret
|
||||
validateSessionSecret(config);
|
||||
|
||||
// Print a warning if config.domain is not set
|
||||
validateDomainIsSet(config);
|
||||
|
||||
// Expose configuration utilities
|
||||
config.utils = {
|
||||
getGlobbedPaths: getGlobbedPaths,
|
||||
|
||||
3
config/env/default.js
vendored
3
config/env/default.js
vendored
@@ -9,6 +9,9 @@ module.exports = {
|
||||
},
|
||||
port: process.env.PORT || 3000,
|
||||
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,
|
||||
// Session Cookie settings
|
||||
sessionCookie: {
|
||||
// session expiration is set by default to 24 hours
|
||||
|
||||
@@ -40,6 +40,7 @@ module.exports.initLocalVariables = function (app) {
|
||||
app.locals.logo = config.logo;
|
||||
app.locals.favicon = config.favicon;
|
||||
app.locals.env = process.env.NODE_ENV;
|
||||
app.locals.domain = config.domain;
|
||||
|
||||
// Passing the request url to environment locals
|
||||
app.use(function (req, res, next) {
|
||||
|
||||
@@ -61,11 +61,14 @@ exports.forgot = function (req, res, next) {
|
||||
if (config.secure && config.secure.ssl === true) {
|
||||
httpTransport = 'https://';
|
||||
}
|
||||
var baseUrl = req.app.get('domain') || httpTransport + req.headers.host;
|
||||
console.log(baseUrl);
|
||||
res.render(path.resolve('modules/users/server/templates/reset-password-email'), {
|
||||
name: user.displayName,
|
||||
appName: config.app.title,
|
||||
url: httpTransport + req.headers.host + '/api/auth/reset/' + token
|
||||
url: baseUrl + '/api/auth/reset/' + token
|
||||
}, function (err, emailHTML) {
|
||||
console.log(emailHTML);
|
||||
done(err, emailHTML, user);
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user