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

Adds a generic DOMAIN configuration environment #1469

Merged
merged 1 commit into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not set, should this default to localhost? Or at least default to localhost in the development config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We kind of take care of that in https://github.com/meanjs/mean/pull/1469/files/77d4a990f52b83d684a6eb73c7e019576163467e#diff-c3841fb7af244bab7b73ea4c3d72055cR64

It also makes it much complicated to default it to something because you don't know if the server is running in http or https, and this causes many more logic tests to run. It's a simple domain/url setting, I don't think we need to make it anymore complex than that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

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