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
node.js reactjs react-router express


source to share


No one has answered this question yet

Check out similar questions:

501
React router urls not working when updated or manually written
59
Webpack vs webpack-dev-server vs webpack-dev-middleware vs webpack-hot-middleware vs etc.
4
Configure webpack-dev-middleware correctly with vuejs project
1
Reading in webpack json resources with webpack-dev-server
1
Emitter assembly with express
0
Using webpack-dev-server 3 with parallel webpack
0
Webpack Dynamic public path?
0
Simple static HTML server in a node
0
Links to external links Webpack Dev Middleware
0
Why does this error occur when starting the nodejs server?



All Articles
Loading...
X
Show
Funny
Dev
Pics