Skip to content

Commit

Permalink
Ensure that SSL options (if provided) are buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
sgress454 committed Feb 2, 2016
1 parent c638573 commit 7ae836b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/hooks/http/initialize.js
Expand Up @@ -31,12 +31,22 @@ module.exports = function(sails) {
var app = sails.hooks.http.app = express();
app.disable('x-powered-by');
// (required by Express 3.x)

// Determine whether or not to create an HTTPS server
var usingSSL = sails.config.ssl === true || (sails.config.ssl.key && sails.config.ssl.cert) || sails.config.ssl.pfx;

// Merge SSL into server options
var serverOptions = sails.config.http.serverOptions || {};
_.extend(serverOptions, sails.config.ssl);

// Lodash 3's _.merge transforms buffers into arrays; if we detect an array, then
// transform it back into a buffer
_.each(['key', 'cert', 'pfx'], function(sslOption) {
if (_.isArray(serverOptions[sslOption])) {
serverOptions[sslOption] = new Buffer(serverOptions[sslOption]);
}
});

// Get the appropriate server creation method for the protocol
var createServer = usingSSL ?
require('https').createServer :
Expand Down Expand Up @@ -117,7 +127,7 @@ module.exports = function(sails) {
// app.use() the configured express middleware
var defaultMiddleware = require('./middleware/defaults')(sails, app);
installHTTPMiddleware(app, defaultMiddleware, sails);

// Note that it is possible for the configured HTTP middleware stack to be shared with the
// core router built into Sails-- this would make the same stack take effect for all virtual requests
// including sockets. Currently, an abbreviated version of this stack is built-in to `lib/router/`
Expand Down

0 comments on commit 7ae836b

Please sign in to comment.