-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·57 lines (47 loc) · 1.53 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import webpack from 'webpack';
import webpackMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import express from 'express';
import path from 'path';
import http from 'http';
import webpackConfig from './webpack.config';
const isProduction = process.env.NODE_ENV === 'production';
const isDeveloping = !isProduction;
const app = express();
const port = 8000;
// Webpack dev server
if (isDeveloping) {
const WEBPACK_PORT = 3001;
const compiler = webpack(webpackConfig);
app.use(webpackMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false,
},
}));
app.use(webpackHotMiddleware(compiler));
app.listen(WEBPACK_PORT, 'localhost', (err) => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log(`WebpackDevServer listening at localhost:${WEBPACK_PORT}`); // eslint-disable-line no-console
});
}
// this is necessary to handle URL correctly since client uses Browser History
app.get('*', (request, response) => {
response.sendFile(path.resolve(__dirname, '', 'index.html'));
});
// We need to use basic HTTP service to proxy
// websocket requests from webpack
const server = http.createServer(app);
server.listen(port, (err) => {
if (err) {
console.log(err); // eslint-disable-line no-console
}
console.log(`Server running on port ${port}`); // eslint-disable-line no-console
});