1
1
'use strict' ;
2
2
3
3
var fs = require ( 'fs' ) ,
4
- union = require ( 'union' ) ,
5
- httpServerCore = require ( './core' ) ,
6
- auth = require ( 'basic-auth' ) ,
7
- httpProxy = require ( 'http-proxy' ) ,
8
- corser = require ( 'corser' ) ,
9
- path = require ( 'path' ) ,
10
- secureCompare = require ( 'secure-compare' ) ;
4
+ union = require ( 'union' ) ,
5
+ httpServerCore = require ( './core' ) ,
6
+ auth = require ( 'basic-auth' ) ,
7
+ httpProxy = require ( 'http-proxy' ) ,
8
+ corser = require ( 'corser' ) ,
9
+ secureCompare = require ( 'secure-compare' ) ;
11
10
12
11
//
13
12
// Remark: backwards compatibility for previous
@@ -35,10 +34,10 @@ function HttpServer(options) {
35
34
this . root = options . root ;
36
35
} else {
37
36
try {
37
+ // eslint-disable-next-line no-sync
38
38
fs . lstatSync ( './public' ) ;
39
39
this . root = './public' ;
40
- }
41
- catch ( err ) {
40
+ } catch ( err ) {
42
41
this . root = './' ;
43
42
}
44
43
}
@@ -47,11 +46,12 @@ function HttpServer(options) {
47
46
this . headers [ 'Accept-Ranges' ] = 'bytes' ;
48
47
49
48
this . cache = (
49
+ // eslint-disable-next-line no-nested-ternary
50
50
options . cache === undefined ? 3600 :
51
51
// -1 is a special case to turn off caching.
52
52
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Preventing_caching
53
- options . cache === - 1 ? 'no-cache, no-store, must-revalidate' :
54
- options . cache // in seconds.
53
+ options . cache === - 1 ? 'no-cache, no-store, must-revalidate' :
54
+ options . cache // in seconds.
55
55
) ;
56
56
this . showDir = options . showDir !== 'false' ;
57
57
this . autoIndex = options . autoIndex !== 'false' ;
@@ -103,7 +103,7 @@ function HttpServer(options) {
103
103
this . headers [ 'Access-Control-Allow-Headers' ] = 'Origin, X-Requested-With, Content-Type, Accept, Range' ;
104
104
if ( options . corsHeaders ) {
105
105
options . corsHeaders . split ( / \s * , \s * / )
106
- . forEach ( function ( h ) { this . headers [ 'Access-Control-Allow-Headers' ] += ', ' + h ; } , this ) ;
106
+ . forEach ( function ( h ) { this . headers [ 'Access-Control-Allow-Headers' ] += ', ' + h ; } , this ) ;
107
107
}
108
108
before . push ( corser . create ( options . corsHeaders ? {
109
109
requestHeaders : this . headers [ 'Access-Control-Allow-Headers' ] . split ( / \s * , \s * / )
@@ -146,7 +146,7 @@ function HttpServer(options) {
146
146
proxy . web ( req , res , {
147
147
target : options . proxy ,
148
148
changeOrigin : true
149
- } , function ( err , req , res , target ) {
149
+ } , function ( err , req , res ) {
150
150
if ( options . logFn ) {
151
151
options . logFn ( req , res , {
152
152
message : err . message ,
@@ -173,7 +173,11 @@ function HttpServer(options) {
173
173
serverOptions . https = options . https ;
174
174
}
175
175
176
- this . server = union . createServer ( serverOptions ) ;
176
+ this . server = serverOptions . https && serverOptions . https . passphrase
177
+ // if passphrase is set, shim must be used as union does not support
178
+ ? require ( './shims/https-server-shim' ) ( serverOptions )
179
+ : union . createServer ( serverOptions ) ;
180
+
177
181
if ( options . timeout !== undefined ) {
178
182
this . server . setTimeout ( options . timeout ) ;
179
183
}
0 commit comments