Organize server creation into new function

This commit is contained in:
Andrew Stewart 2014-06-04 13:21:15 -07:00
parent a4cfc4b8ec
commit 789ce02ad0
1 changed files with 18 additions and 16 deletions

View File

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