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.
This commit is contained in:
Javier Cervantes 2014-04-23 17:56:42 -05:00
parent 8f746f1d27
commit 40b3db1dce
2 changed files with 15 additions and 7 deletions

View File

@ -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);
}
});
};

View File

@ -50,7 +50,7 @@ var Cylon = (function() {
key: null,
auth: {},
CORS: null,
ssl: false
ssl: null
};
this.robot = bind(this.robot, this);