From 40b3db1dce2dbfd45b02b8b294e2f2d54b895a4e Mon Sep 17 00:00:00 2001 From: Javier Cervantes <1.27201@gmail.com> Date: Wed, 23 Apr 2014 17:56:42 -0500 Subject: [PATCH] Changing how ssl is configured Expected configuration: { ssl: { key: "/path/to/key", cert: "/path/to/cert" } } If ssl is false, use plain HTTP. If it's an empty object (the default) use our self-signed certs. If it's set up like above, use the provided certs. --- lib/api.js | 20 ++++++++++++++------ lib/cylon.js | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/api.js b/lib/api.js index 412339e..8996241 100644 --- a/lib/api.js +++ b/lib/api.js @@ -25,17 +25,22 @@ namespace("Cylon", function() { if (opts == null) { opts = {}; } this.opts = opts; - this.host = opts.host || "127.0.0.1"; this.port = opts.port || "3000"; + if (opts.ssl == false) { + this.ssl = false; + } else { + this.ssl = opts.ssl || {key: __dirname + "/ssl/server.key", cert: __dirname + "/ssl/server.crt"}; + } + this.master = opts.master; this.server = express(); - if (opts.ssl) { + if (!!this.ssl.cert && !!this.ssl.key) { var options = { - cert: fs.readFileSync(opts.cert || __dirname + "/ssl/server.crt"), - key: fs.readFileSync(opts.key || __dirname + "/ssl/server.key") + cert: fs.readFileSync(this.ssl.cert), + key: fs.readFileSync(this.ssl.key) } this.server.node = https.createServer(options, this.server); @@ -65,9 +70,12 @@ namespace("Cylon", function() { this.server.node.listen(this.port, this.host, null, function() { var title = self.server.get('title'); Logger.info(title + " is now online."); - Logger.info("Listening at https://" + self.host + ":" + self.port); - if(!self.opts.ssl) { + + if(self.opts.ssl == false) { + Logger.info("Listening at http://" + self.host + ":" + self.port); Logger.warn("API using insecure connection. We recommend using an SSL certificate with Cylon."); + } else { + Logger.info("Listening at https://" + self.host + ":" + self.port); } }); }; diff --git a/lib/cylon.js b/lib/cylon.js index 0fc9536..dd1f6c3 100644 --- a/lib/cylon.js +++ b/lib/cylon.js @@ -50,7 +50,7 @@ var Cylon = (function() { key: null, auth: {}, CORS: null, - ssl: false + ssl: null }; this.robot = bind(this.robot, this);