-
Notifications
You must be signed in to change notification settings - Fork 31
/
devServer.js
46 lines (37 loc) · 1.1 KB
/
devServer.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
const moment = require('moment');
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackConfig = require('./webpack.config');
const analyticsRouter = require('./analytics');
const env = require('./env');
const router = new express.Router();
if (env.isDevelopment) {
const compiler = webpack(webpackConfig);
router.use(webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: false,
quiet: true,
historyApiFallback: true,
}));
router.use(webpackHotMiddleware(compiler, {
log: () => null,
heartbeat: 10 * 1000,
reload: true,
}));
router.use('/analytics', analyticsRouter);
} else if (env.isProduction) {
router.use('/', express.static(
'./build',
{
maxAge: moment.duration(1, 'y').asMilliseconds(),
},
));
}
const app = express();
app.use(router);
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});