Skip to content

Commit 646cfbd

Browse files
author
Adam Rudd
committed
Accept options object or paths in mqtt.createSecureServer
Note: calling this as 'string string function' is now deprecated, include a warning in future and update docs
1 parent 356da39 commit 646cfbd

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/mqtt.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ var net = require('net')
88
, MqttSecureServer = require('./server').MqttSecureServer
99
, MqttClient = require('./client')
1010
, MqttConnection = require('./connection')
11-
, tls = require("tls")
12-
, fs = require("fs");
11+
, tls = require('tls')
12+
, fs = require('fs');
1313

1414
var defaultPort = 1883
1515
, defaultHost = 'localhost';
@@ -134,14 +134,26 @@ module.exports.createServer = function(listener) {
134134
/**
135135
* createSecureServer - create a tls secured MQTT server
136136
*
137+
* @param {Object} opts - server options
138+
* - OR
137139
* @param {String} keyPath - path to private key
138140
* @param {String} certPath - path to public cert
139-
* @param {Function} listener - called on new client conns
141+
* @param {Function} [listener] - called on new client conns
140142
*/
141-
142143
module.exports.createSecureServer =
143-
function(keyPath, certPath, listener) {
144-
return new MqttSecureServer(keyPath, certPath, listener);
144+
function (keyPath, certPath, listener) {
145+
var opts = {};
146+
147+
// Deprecated style
148+
if ('string' === typeof keyPath && 'string' === typeof certPath) {
149+
// TODO: deprecation warning?
150+
opts.key = fs.readFileSync(keyPath);
151+
opts.cert = fs.readFileSync(certPath);
152+
} else if ('object' === typeof keyPath) {
153+
opts = keyPath;
154+
}
155+
156+
return new MqttSecureServer(opts, listener);
145157
};
146158

147159
/**

0 commit comments

Comments
 (0)