1
-
2
1
var fs = require ( 'fs' ) ;
3
2
var qs = require ( 'qs' ) ;
4
3
var path = require ( 'path' ) ;
5
4
var util = require ( 'util' ) ;
6
5
var http = require ( 'http' ) ;
6
+ var https = require ( 'https' ) ;
7
7
var events = require ( 'events' ) ;
8
8
var parse = require ( 'url' ) . parse ;
9
9
var debug = require ( 'debug' ) ( 'tinylr:server' ) ;
@@ -12,8 +12,6 @@ var constants = require('constants');
12
12
13
13
var config = require ( '../package.json' ) ;
14
14
15
- module . exports = Server ;
16
-
17
15
function Server ( options ) {
18
16
options = this . options = options || { } ;
19
17
events . EventEmitter . call ( this ) ;
@@ -32,13 +30,20 @@ function Server(options) {
32
30
this . configure ( options . app ) ;
33
31
}
34
32
33
+ module . exports = Server ;
34
+
35
35
util . inherits ( Server , events . EventEmitter ) ;
36
36
37
37
Server . prototype . configure = function configure ( app ) {
38
38
debug ( 'Configuring %s' , app ? 'connect / express application' : 'HTTP server' ) ;
39
39
40
40
if ( ! app ) {
41
- this . server = http . createServer ( this . handler . bind ( this ) ) ;
41
+ if ( this . options . key && this . options . cert ) {
42
+ this . server = https . createServer ( this . options , this . handler . bind ( this ) ) ;
43
+ }
44
+ else {
45
+ this . server = http . createServer ( this . handler . bind ( this ) ) ;
46
+ }
42
47
this . server . on ( 'upgrade' , this . websocketify . bind ( this ) ) ;
43
48
this . server . on ( 'error' , this . error . bind ( this ) ) ;
44
49
return this ;
0 commit comments