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:
Liran Tal
2016-09-01 22:37:43 +03:00
committed by GitHub
parent 54ae7dc564
commit cf246babd1
4 changed files with 19 additions and 1 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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) {

View File

@@ -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);
});
},