Files
graylog2-server/graylog2-web-interface/devServer.js
Edmundo Alvarez be7a102937 Web dev improvements (#4388)
* Customize port number in dev-server

Let users customize port number by passing `--port=<port>` as argument.
If the port is already taken, we will start the web interface in a
random one.

* Remove alternative dev setup

* Revert dev server port

Changed it accidentally during some tests.

* Remove react-hot-loader dev build

The `start` build using HMR alongside react-hot-loader was already not
working as it should with webpack-dev-server. Modules got reloaded, but the
application state was reset on every change.

I have been trying a couple of times to make HMR work with the new express
dev server, but I just managed to reproduce what it achieved in the
previous build (reloading the whole component tree, but losing the state).
All of that making the current webpack configuration more complicated.

I think react-hot-loader is a good idea that can be helpful specially when
styling components, but currently I see that it produces way too maintenance
burden for the benefits it provides. Also, nobody in the team seems to be
using it for development.

Long story short, this commit removes react-hot-loader from our dev build. We
still use Webpack HMR to reload the browser.

The commit also replaces the `start` script with `start-nohmr`, so
running `yarn start` will use the no react-hot-loader dev server.

* Update README file

- Include details to use yarn in development
- Remove old warnings and information
- Remove mentions of the react-hot-loader build
- Update information on upgrade packages
- Update information on IntelliJ setup

* Improve some texts in the README

* Add documentation on how to customize port number

* Fix linter errors
2017-12-05 11:47:30 +01:00

55 lines
1.6 KiB
JavaScript

const express = require('express');
const webpack = require('webpack');
const compress = require('compression');
const history = require('connect-history-api-fallback');
const http = require('http');
const yargs = require('yargs');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackConfig = require('./webpack.bundled');
const DEFAULT_PORT = 8080;
const app = express();
const vendorConfig = webpackConfig[0];
const appConfig = webpackConfig[1];
// Use two compilers to avoid re-compiling the vendor config on every change.
// We assume dependencies won't change while the server is running.
const vendorCompiler = webpack(vendorConfig);
const appCompiler = webpack(appConfig);
app.use(compress()); // Enables compression middleware
app.use(history()); // Enables HTML5 History API middleware
app.use(webpackDevMiddleware(vendorCompiler, {
publicPath: appConfig.output.publicPath,
lazy: false,
noInfo: true,
}));
app.use(webpackDevMiddleware(appCompiler, {
publicPath: appConfig.output.publicPath,
lazy: false,
noInfo: true,
}));
app.use(webpackHotMiddleware(appCompiler));
const server = http.createServer(app);
const argv = yargs.argv;
server
.listen(argv.port || DEFAULT_PORT, () => {
console.log(`Graylog web interface listening on port ${server.address().port}!\n`);
})
.on('error', (error) => {
if (error.code === 'EADDRINUSE') {
console.error(`Port ${argv.port || DEFAULT_PORT} already in use, will use a random one instead...`);
server.listen(0);
} else {
throw error;
}
});