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:
parent
8f746f1d27
commit
40b3db1dce
20
lib/api.js
20
lib/api.js
|
@ -25,17 +25,22 @@ namespace("Cylon", function() {
|
||||||
if (opts == null) { opts = {}; }
|
if (opts == null) { opts = {}; }
|
||||||
|
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
|
|
||||||
this.host = opts.host || "127.0.0.1";
|
this.host = opts.host || "127.0.0.1";
|
||||||
this.port = opts.port || "3000";
|
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.master = opts.master;
|
||||||
this.server = express();
|
this.server = express();
|
||||||
|
|
||||||
if (opts.ssl) {
|
if (!!this.ssl.cert && !!this.ssl.key) {
|
||||||
var options = {
|
var options = {
|
||||||
cert: fs.readFileSync(opts.cert || __dirname + "/ssl/server.crt"),
|
cert: fs.readFileSync(this.ssl.cert),
|
||||||
key: fs.readFileSync(opts.key || __dirname + "/ssl/server.key")
|
key: fs.readFileSync(this.ssl.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server.node = https.createServer(options, this.server);
|
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() {
|
this.server.node.listen(this.port, this.host, null, function() {
|
||||||
var title = self.server.get('title');
|
var title = self.server.get('title');
|
||||||
Logger.info(title + " is now online.");
|
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.");
|
Logger.warn("API using insecure connection. We recommend using an SSL certificate with Cylon.");
|
||||||
|
} else {
|
||||||
|
Logger.info("Listening at https://" + self.host + ":" + self.port);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,7 +50,7 @@ var Cylon = (function() {
|
||||||
key: null,
|
key: null,
|
||||||
auth: {},
|
auth: {},
|
||||||
CORS: null,
|
CORS: null,
|
||||||
ssl: false
|
ssl: null
|
||||||
};
|
};
|
||||||
|
|
||||||
this.robot = bind(this.robot, this);
|
this.robot = bind(this.robot, this);
|
||||||
|
|
Loading…
Reference in New Issue