Organize server creation into new function
This commit is contained in:
parent
a4cfc4b8ec
commit
789ce02ad0
34
lib/api.js
34
lib/api.js
|
@ -27,22 +27,7 @@ var API = module.exports = function API(opts) {
|
|||
this[d] = opts.hasOwnProperty(d) ? opts[d] : this.defaults[d];
|
||||
}
|
||||
|
||||
this.server = express();
|
||||
|
||||
//configure ssl if requested
|
||||
if (this.ssl && typeof(this.ssl) === 'object') {
|
||||
var https = require('https');
|
||||
|
||||
var options = {
|
||||
key: fs.readFileSync(this.ssl.key),
|
||||
cert: fs.readFileSync(this.ssl.cert)
|
||||
};
|
||||
|
||||
this.server.node = https.createServer(options, this.server);
|
||||
} else {
|
||||
Logger.warn("API using insecure connection. We recommend using an SSL certificate with Cylon.")
|
||||
this.server.node = this.server;
|
||||
}
|
||||
this.createServer();
|
||||
|
||||
var authfn = this.setupAuth();
|
||||
this.server.use(authfn);
|
||||
|
@ -65,6 +50,23 @@ API.prototype.defaults = {
|
|||
}
|
||||
};
|
||||
|
||||
API.prototype.createServer = function createServer() {
|
||||
this.server = express();
|
||||
|
||||
//configure ssl if requested
|
||||
if (this.ssl && typeof(this.ssl) === 'object') {
|
||||
var https = require('https');
|
||||
|
||||
this.server.node = https.createServer({
|
||||
key: fs.readFileSync(this.ssl.key),
|
||||
cert: fs.readFileSync(this.ssl.cert)
|
||||
}, this.server);
|
||||
} else {
|
||||
Logger.warn("API using insecure connection. We recommend using an SSL certificate with Cylon.")
|
||||
this.server.node = this.server;
|
||||
}
|
||||
};
|
||||
|
||||
API.prototype.setupAuth = function setupAuth() {
|
||||
var authfn = function auth(req, res, next) { next(); };
|
||||
|
||||
|
|
Loading…
Reference in New Issue