11'use strict' ;
22
33var 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' ) ;
1110
1211//
1312// Remark: backwards compatibility for previous
@@ -35,10 +34,10 @@ function HttpServer(options) {
3534 this . root = options . root ;
3635 } else {
3736 try {
37+ // eslint-disable-next-line no-sync
3838 fs . lstatSync ( './public' ) ;
3939 this . root = './public' ;
40- }
41- catch ( err ) {
40+ } catch ( err ) {
4241 this . root = './' ;
4342 }
4443 }
@@ -47,11 +46,12 @@ function HttpServer(options) {
4746 this . headers [ 'Accept-Ranges' ] = 'bytes' ;
4847
4948 this . cache = (
49+ // eslint-disable-next-line no-nested-ternary
5050 options . cache === undefined ? 3600 :
5151 // -1 is a special case to turn off caching.
5252 // 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.
5555 ) ;
5656 this . showDir = options . showDir !== 'false' ;
5757 this . autoIndex = options . autoIndex !== 'false' ;
@@ -103,7 +103,7 @@ function HttpServer(options) {
103103 this . headers [ 'Access-Control-Allow-Headers' ] = 'Origin, X-Requested-With, Content-Type, Accept, Range' ;
104104 if ( options . corsHeaders ) {
105105 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 ) ;
107107 }
108108 before . push ( corser . create ( options . corsHeaders ? {
109109 requestHeaders : this . headers [ 'Access-Control-Allow-Headers' ] . split ( / \s * , \s * / )
@@ -146,7 +146,7 @@ function HttpServer(options) {
146146 proxy . web ( req , res , {
147147 target : options . proxy ,
148148 changeOrigin : true
149- } , function ( err , req , res , target ) {
149+ } , function ( err , req , res ) {
150150 if ( options . logFn ) {
151151 options . logFn ( req , res , {
152152 message : err . message ,
@@ -173,7 +173,11 @@ function HttpServer(options) {
173173 serverOptions . https = options . https ;
174174 }
175175
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+
177181 if ( options . timeout !== undefined ) {
178182 this . server . setTimeout ( options . timeout ) ;
179183 }
0 commit comments