Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
feat(config): adds a generic DOMAIN configuration environment (#1469)
Browse files Browse the repository at this point in the history
Generic DOMAI configuration environment variable, useful for setting links to an app
in reset email templates, and other cases.

Fixes #871 and #847
  • Loading branch information
lirantal authored Sep 1, 2016
1 parent 54ae7dc commit cf246ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions config/env/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},
Expand Down

0 comments on commit cf246ba

Please sign in to comment.