Skip to content

Commit 44e0e88

Browse files
committed
Allow regular strings and objects as SSL options.
1 parent dd6bdbc commit 44e0e88

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

lib/LinkedDataFragmentsServer.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@ function LinkedDataFragmentsServer(options) {
1111
// Create the HTTP(S) server
1212
var server, sockets = 0;
1313
switch (options.protocol) {
14-
case 'https':
15-
var ssl = options.ssl || {};
16-
17-
var httpsOptions = _.mapValues(ssl.keys || {},
18-
function (v) {
19-
return _.isArray(v) ? _.map(v, function (w) { return fs.readFileSync(w, 'ascii'); }) : fs.readFileSync(v, 'ascii');
20-
});
21-
22-
server = require('https').createServer(httpsOptions);
23-
break;
2414
case 'http':
2515
server = require('http').createServer();
2616
break;
17+
case 'https':
18+
var httpsOptions = _.mapValues((options.ssl || {}).keys || {}, readHttpsOption);
19+
server = require('https').createServer(httpsOptions);
20+
break;
2721
default:
2822
throw new Error('The configured protocol ' + options.protocol + ' is invalid.');
2923
}
30-
24+
// Copy over members
3125
for (var member in LinkedDataFragmentsServer.prototype)
3226
server[member] = LinkedDataFragmentsServer.prototype[member];
3327

@@ -135,4 +129,17 @@ LinkedDataFragmentsServer.prototype.stop = function () {
135129
}, this);
136130
};
137131

132+
// Reads the value of an option for the https module
133+
function readHttpsOption(value) {
134+
// Read each value of an array
135+
if (_.isArray(value))
136+
return value.map(readHttpsOption);
137+
// Certificates and keys can be strings or files
138+
else if (_.isString(value) && fs.existsSync(value))
139+
return fs.readFileSync(value);
140+
// Other strings and regular objects are also allowed
141+
else
142+
return value;
143+
}
144+
138145
module.exports = LinkedDataFragmentsServer;

0 commit comments

Comments
 (0)