fixing up SSL support on startup to fallback to non-SSL mode if files are not present

This commit is contained in:
Liran Tal
2015-07-17 11:16:25 +03:00
parent e1605b635b
commit 03b7f6ffda
3 changed files with 23 additions and 2 deletions

View File

@@ -56,9 +56,9 @@ var validateEnvironmentVariable = function() {
console.log();
if (!environmentFiles.length) {
if (process.env.NODE_ENV) {
console.error(chalk.red('No configuration file found for "' + process.env.NODE_ENV + '" environment using development instead'));
console.error(chalk.red('+ Error: No configuration file found for "' + process.env.NODE_ENV + '" environment using development instead'));
} else {
console.error(chalk.red('NODE_ENV is not defined! Using default development environment'));
console.error(chalk.red('+ Error: NODE_ENV is not defined! Using default development environment'));
}
process.env.NODE_ENV = 'development';
}
@@ -66,6 +66,24 @@ var validateEnvironmentVariable = function() {
console.log(chalk.white(''));
};
/**
* Validate Secure=true parameter can actually be turned on
* because it requires certs and key files to be available
*/
var validateSecureMode = function(config) {
if (config.secure !== true)
return true;
var privateKey = fs.existsSync('./config/sslcerts/key.pem');
var certificate = fs.existsSync('./config/sslcerts/cert.pem');
if (!privateKey || !certificate) {
chalk.red(console.log('+ Error: Certificate file or key file is missing, falling back to non-SSL mode'));
config.secure = false;
}
};
/**
* Initialize global configuration files
*/
@@ -148,6 +166,9 @@ var initGlobalConfig = function() {
// Initialize global globbed folders
initGlobalConfigFolders(config, assets);
// Validate Secure SSL mode can be used
validateSecureMode(config);
// Expose configuration utilities
config.utils = {
getGlobbedPaths: getGlobbedPaths

0
scripts/generate-ssl-certs.sh Normal file → Executable file
View File

0
scripts/reset-password.js Normal file → Executable file
View File