Skip to content

Commit

Permalink
[bug] fix webpack dev server memfs serving
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed May 29, 2019
1 parent aebd9af commit f0e0777
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ class Middleware {
this.publicPath = webpackDevOptions.publicPath || "/";
this.listAssetPath = urlJoin(this.publicPath, "/");

this.cwdMemIndex = serveIndex(process.cwd(), {
// webpack dev middleware's memfs root is where the actual output from webpack
this.memFsCwd = "/";
this.cwdMemIndex = serveIndex(this.memFsCwd, {
icons: true,
hidden: true,
fs: this.devMiddleware.fileSystem
Expand Down Expand Up @@ -322,10 +324,10 @@ doReload(1); </script></body></html>`)
);
}

const serveStatic = (baseUrl, fileSystem, indexServer) => {
const serveStatic = (baseUrl, fileSystem, indexServer, cwd) => {
req.originalUrl = req.url; // this is what express saves to, else serve-index nukes
req.url = req.url.substr(baseUrl.length) || "/";
const fullPath = Path.join(process.cwd(), req.url);
const fullPath = Path.join(cwd || process.cwd(), req.url);

return new Promise((resolve, reject) => {
fileSystem.stat(fullPath, (err, stats) => {
Expand Down Expand Up @@ -407,7 +409,8 @@ ${listDirectoryHtml(this.listAssetPath, outputPath)}
return serveStatic(
this.cwdContextBaseUrl,
this.devMiddleware.fileSystem,
this.cwdMemIndex
this.cwdMemIndex,
this.memFsCwd
).catch(err => sendStaticServeError("reading webpack mem fs", err));
} else if (req.url.startsWith(this.reporterUrl) || this.returnReporter) {
return serveReporter(this.webpackDev.lastReporterOptions);
Expand Down

0 comments on commit f0e0777

Please sign in to comment.