File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -69,9 +69,10 @@ app.use(webpackMiddleware(webpack({
69
69
publicPath: " /assets/" ,
70
70
// public path to bind the middleware to
71
71
// use the same as in webpack
72
-
72
+
73
73
index: " index.html" ,
74
- // the index path for web server
74
+ // The index path for web server, defaults to "index.html".
75
+ // If falsy (but not undefined), the server will not respond to requests to the root URL.
75
76
76
77
headers: { " X-Custom-Header" : " yes" },
77
78
// custom headers
Original file line number Diff line number Diff line change @@ -47,7 +47,15 @@ module.exports = function(compiler, options) {
47
47
var stat = context . fs . statSync ( filename ) ;
48
48
if ( ! stat . isFile ( ) ) {
49
49
if ( stat . isDirectory ( ) ) {
50
- filename = pathJoin ( filename , context . options . index || "index.html" ) ;
50
+ var index = context . options . index ;
51
+
52
+ if ( index === undefined || index === true ) {
53
+ index = "index.html" ;
54
+ } else if ( ! index ) {
55
+ throw "next" ;
56
+ }
57
+
58
+ filename = pathJoin ( filename , index ) ;
51
59
stat = context . fs . statSync ( filename ) ;
52
60
if ( ! stat . isFile ( ) ) throw "next" ;
53
61
} else {
Original file line number Diff line number Diff line change @@ -101,6 +101,27 @@ describe("Server", function() {
101
101
} ) ;
102
102
} ) ;
103
103
104
+ describe ( "no index mode" , function ( ) {
105
+ before ( function ( done ) {
106
+ app = express ( ) ;
107
+ var compiler = webpack ( webpackConfig ) ;
108
+ app . use ( middleware ( compiler , {
109
+ stats : "errors-only" ,
110
+ quiet : true ,
111
+ index : false ,
112
+ publicPath : "/" ,
113
+ } ) ) ;
114
+ listen = listenShorthand ( done ) ;
115
+ } ) ;
116
+ after ( close ) ;
117
+
118
+ it ( "request to directory" , function ( done ) {
119
+ request ( app ) . get ( "/" )
120
+ . expect ( "Content-Type" , "text/html; charset=utf-8" )
121
+ . expect ( 404 , done ) ;
122
+ } ) ;
123
+ } ) ;
124
+
104
125
describe ( "lazy mode" , function ( ) {
105
126
before ( function ( done ) {
106
127
app = express ( ) ;
You can’t perform that action at this time.
0 commit comments