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

Commit

Permalink
adding support for a configurable ssl-mode and and ssl cert/key files…
Browse files Browse the repository at this point in the history
… in the environment configuration
  • Loading branch information
lirantal committed Aug 17, 2015
1 parent 1f0f1b7 commit 384fb7d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down
6 changes: 5 additions & 1 deletion config/env/production.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
4 changes: 3 additions & 1 deletion config/lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions config/lib/socket.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 384fb7d

Please sign in to comment.