From 68db18b2399fe8cd93ce5834079f9511447099d5 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Wed, 28 Aug 2013 20:35:53 -0700 Subject: [PATCH] Enable an https lr server By passing the contents of cert files, we can enable an https version of the lr server which is super handy for debugging https. --- lib/server.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/server.js b/lib/server.js index 5f952eb..193c2db 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,9 +1,9 @@ - var fs = require('fs'); var qs = require('qs'); var path = require('path'); var util = require('util'); var http = require('http'); +var https = require('https'); var events = require('events'); var parse = require('url').parse; var debug = require('debug')('tinylr:server'); @@ -12,8 +12,6 @@ var constants = require('constants'); var config = require('../package.json'); -module.exports = Server; - function Server(options) { options = this.options = options || {}; events.EventEmitter.call(this); @@ -32,13 +30,20 @@ function Server(options) { this.configure(options.app); } +module.exports = Server; + util.inherits(Server, events.EventEmitter); Server.prototype.configure = function configure(app) { debug('Configuring %s', app ? 'connect / express application' : 'HTTP server'); if(!app) { - this.server = http.createServer(this.handler.bind(this)); + if (this.options.key && this.options.cert) { + this.server = https.createServer(this.options, this.handler.bind(this)); + } + else { + this.server = http.createServer(this.handler.bind(this)); + } this.server.on('upgrade', this.websocketify.bind(this)); this.server.on('error', this.error.bind(this)); return this;