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
@@ -33,13 +32,12 @@ function HttpServer(options) {
33
32
34
33
if ( options . root ) {
35
34
this . root = options . root ;
36
- }
37
- else {
35
+ } else {
38
36
try {
37
+ // eslint-disable-next-line no-sync
39
38
fs . lstatSync ( './public' ) ;
40
39
this . root = './public' ;
41
- }
42
- catch ( err ) {
40
+ } catch ( err ) {
43
41
this . root = './' ;
44
42
}
45
43
}
@@ -48,11 +46,12 @@ function HttpServer(options) {
48
46
this . headers [ 'Accept-Ranges' ] = 'bytes' ;
49
47
50
48
this . cache = (
49
+ // eslint-disable-next-line no-nested-ternary
51
50
options . cache === undefined ? 3600 :
52
51
// -1 is a special case to turn off caching.
53
52
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Preventing_caching
54
- options . cache === - 1 ? 'no-cache, no-store, must-revalidate' :
55
- options . cache // in seconds.
53
+ options . cache === - 1 ? 'no-cache, no-store, must-revalidate' :
54
+ options . cache // in seconds.
56
55
) ;
57
56
this . showDir = options . showDir !== 'false' ;
58
57
this . autoIndex = options . autoIndex !== 'false' ;
@@ -104,7 +103,7 @@ function HttpServer(options) {
104
103
this . headers [ 'Access-Control-Allow-Headers' ] = 'Origin, X-Requested-With, Content-Type, Accept, Range' ;
105
104
if ( options . corsHeaders ) {
106
105
options . corsHeaders . split ( / \s * , \s * / )
107
- . forEach ( function ( h ) { this . headers [ 'Access-Control-Allow-Headers' ] += ', ' + h ; } , this ) ;
106
+ . forEach ( function ( h ) { this . headers [ 'Access-Control-Allow-Headers' ] += ', ' + h ; } , this ) ;
108
107
}
109
108
before . push ( corser . create ( options . corsHeaders ? {
110
109
requestHeaders : this . headers [ 'Access-Control-Allow-Headers' ] . split ( / \s * , \s * / )
@@ -146,7 +145,7 @@ function HttpServer(options) {
146
145
proxy . web ( req , res , {
147
146
target : options . proxy ,
148
147
changeOrigin : true
149
- } , function ( err , req , res , target ) {
148
+ } , function ( err , req , res ) {
150
149
if ( options . logFn ) {
151
150
options . logFn ( req , res , {
152
151
message : err . message ,
0 commit comments