Skip to content

Commit b5efecb

Browse files
committed
Merge pull request #16 from ampedandwired/serve_index_html
Check for index.html when serving directories
2 parents 6306446 + 82d31a2 commit b5efecb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

middleware.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
var path = require("path");
56
var MemoryFileSystem = require("memory-fs");
67
var mime = require("mime");
78

@@ -124,15 +125,23 @@ module.exports = function(compiler, options) {
124125
function webpackDevMiddleware(req, res, next) {
125126
var filename = getFilenameFromUrl(req.url);
126127
if (filename === false) return next();
127-
128+
128129
// in lazy mode, rebuild on bundle request
129130
if(options.lazy && filename === pathJoin(compiler.outputPath, options.filename))
130131
rebuild();
131132
// delay the request until we have a vaild bundle
132133
ready(function() {
133134
try {
134135
var stat = fs.statSync(filename);
135-
if(!stat.isFile()) throw "next";
136+
if(!stat.isFile()) {
137+
if (stat.isDirectory()) {
138+
filename = path.join(filename, "index.html");
139+
stat = fs.statSync(filename);
140+
if(!stat.isFile()) throw "next";
141+
} else {
142+
throw "next";
143+
}
144+
}
136145
} catch(e) {
137146
return next();
138147
}

0 commit comments

Comments
 (0)