diff --git a/config/config.js b/config/config.js index 624cf2ce3f..82070cf82e 100644 --- a/config/config.js +++ b/config/config.js @@ -72,18 +72,18 @@ var validateEnvironmentVariable = function () { */ var validateSecureMode = function (config) { - if (config.secure !== true) { + if (!config.secure || config.secure.ssl !== true) { return true; } - var privateKey = fs.existsSync('./config/sslcerts/key.pem'); - var certificate = fs.existsSync('./config/sslcerts/cert.pem'); + var privateKey = fs.existsSync(path.resolve(config.secure.privateKey)); + var certificate = fs.existsSync(path.resolve(config.secure.certificate)); if (!privateKey || !certificate) { console.log(chalk.red('+ Error: Certificate file or key file is missing, falling back to non-SSL mode')); console.log(chalk.red(' To create them, simply run the following from your shell: sh ./scripts/generate-ssl-certs.sh')); console.log(); - config.secure = false; + config.secure.ssl = false; } }; diff --git a/config/env/production.js b/config/env/production.js index 63c7f3dc45..29fd2f8071 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -1,7 +1,11 @@ 'use strict'; module.exports = { - secure: true, + secure: { + ssl: true, + privateKey: './config/sslcerts/key.pem', + certificate: './config/sslcerts/cert.pem' + }, port: process.env.PORT || 8443, db: { uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean', diff --git a/config/lib/express.js b/config/lib/express.js index f2152c4d55..ce9db03771 100644 --- a/config/lib/express.js +++ b/config/lib/express.js @@ -26,7 +26,9 @@ module.exports.initLocalVariables = function (app) { // Setting application local variables app.locals.title = config.app.title; app.locals.description = config.app.description; - app.locals.secure = config.secure; + if (config.secure && config.secure.ssl === true) { + app.locals.secure = config.secure.ssl; + } app.locals.keywords = config.app.keywords; app.locals.googleAnalyticsTrackingID = config.app.googleAnalyticsTrackingID; app.locals.facebookAppId = config.facebook.clientID; diff --git a/config/lib/socket.io.js b/config/lib/socket.io.js index aa613c267c..0c13d2e558 100644 --- a/config/lib/socket.io.js +++ b/config/lib/socket.io.js @@ -15,10 +15,10 @@ var config = require('../config'), // Define the Socket.io configuration method module.exports = function (app, db) { var server; - if (config.secure === true) { + if (config.secure && config.secure.ssl === true) { // Load SSL key and certificate - var privateKey = fs.readFileSync('./config/sslcerts/key.pem', 'utf8'); - var certificate = fs.readFileSync('./config/sslcerts/cert.pem', 'utf8'); + var privateKey = fs.readFileSync(path.resolve(config.secure.privateKey), 'utf8'); + var certificate = fs.readFileSync(path.resolve(config.secure.certificate), 'utf8'); var options = { key: privateKey, cert: certificate,