@@ -23,7 +23,6 @@ function toAssume(uri, extns) {
23
23
}
24
24
25
25
function find ( uri , extns ) {
26
- if ( ! ! ~ uri . lastIndexOf ( '.' ) ) return FILES [ uri ] ;
27
26
let i = 0 , data , arr = toAssume ( uri , extns ) ;
28
27
for ( ; i < arr . length ; i ++ ) {
29
28
if ( data = FILES [ arr [ i ] ] ) break ;
@@ -80,12 +79,11 @@ module.exports = function (dir, opts={}) {
80
79
81
80
if ( opts . dev ) {
82
81
return function ( req , res , next ) {
83
- let uri = decodeURIComponent ( req . path || req . pathname || parser ( req ) . pathname ) ;
84
- let arr = uri . includes ( '.' ) ? [ uri ] : toAssume ( uri , extensions ) ;
85
- let file = arr . map ( x => join ( dir , x ) ) . find ( fs . existsSync ) ;
86
- if ( ! file ) return next ? next ( ) : isNotFound ( req , res ) ;
87
-
88
- let stats = fs . statSync ( file ) ;
82
+ let stats , file , uri = decodeURIComponent ( req . path || req . pathname || parser ( req ) . pathname ) ;
83
+ let arr = [ uri ] . concat ( toAssume ( uri , extensions ) ) . map ( x => join ( dir , x ) ) . filter ( fs . existsSync ) ;
84
+ while ( file = arr . shift ( ) ) {
85
+ stats = fs . statSync ( file ) ;
86
+ if ( stats . isDirectory ( ) ) continue ;
89
87
setHeaders ( res , uri , stats ) ;
90
88
send ( req , res , file , stats , {
91
89
'Content-Type' : mime . getType ( file ) ,
@@ -94,6 +92,7 @@ module.exports = function (dir, opts={}) {
94
92
} ) ;
95
93
}
96
94
}
95
+ }
97
96
98
97
let cc = opts . maxAge != null && `public,max-age=${ opts . maxAge } ` ;
99
98
if ( cc && opts . immutable ) cc += ',immutable' ;
@@ -117,7 +116,7 @@ module.exports = function (dir, opts={}) {
117
116
118
117
return function ( req , res , next ) {
119
118
let pathname = decodeURIComponent ( req . path || req . pathname || parser ( req ) . pathname ) ;
120
- let data = find ( pathname , extensions ) ;
119
+ let data = FILES [ pathname ] || find ( pathname , extensions ) ;
121
120
if ( ! data ) return next ? next ( ) : isNotFound ( req , res ) ;
122
121
123
122
setHeaders ( res , pathname , data . stats ) ;
0 commit comments