Webpack-dev-middleware returns 404 on update
I am trying to set up webpack-dev-middleware with action-redux app. If I refreshed the home page I got a 200 status code. But if I refreshed on any other page ('/ signin') I would get a 404 error.
After some Googling, I found this on Github :
var express = require('express');
var app = express();
var webpack = require('webpack');
var path = require('path');
var compiler = webpack(require('./webpack.config.js'));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: '/'
}));
app.use('*', function (req, res, next) {
var filename = path.join(compiler.outputPath,'index.html');
compiler.outputFileSystem.readFile(filename, function(err, result){
if (err) {
return next(err);
}
res.set('content-type','text/html');
res.send(result);
res.end();
});
});
app.listen(3000);
It works, but I'm not sure why. I think index.html is being fed into memory, which is not a problem on the master page, but for all other pages. In particular, I can't figure out what it does compiler.outputFilesystem
. When I console.log(compiler.outputFilesystem)
, I get:
outputFileSystem: MemoryFileSystem { data: {} }
How can an object with an empty property serve index.html in memory?
+3
source to share
No one has answered this question yet
Check out similar questions: