we have lecasy application written using grunt. It also uses this thing https://github.com/gruntjs/grunt-contrib-connect which gives us possibility to use array of middlewares so that we are able now to add or unshift middleware like so:
grunt.initConfig({
connect: {
server: {
options: {
middleware: function(connect, options, middlewares) {
// inject a custom middleware into the array of default middlewares
middlewares.unshift(function(req, res, next) {
if (req.url !== '/hello/world') return next();
res.end('Hello, world from port #' + options.port + '!');
});
return middlewares;
},
},
},
},
});
Now we are migration our project to webpack and trying to achieve the same behavior with webpack:
var server = new WebpackDevServer(webpack(config), {
//publicPath: config.output.publicPath,
hot: true,
port: 32728,
// historyApiFallback: true,
setup: function(app) {
console.dir(app);
app.use(function(req, res, next) {
// how to access array of middlewares here ?
}
},
stats: {
colors: true
}
});
server.listen(32728);