-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·27 lines (22 loc) · 801 Bytes
/
server.js
File metadata and controls
executable file
·27 lines (22 loc) · 801 Bytes
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
import path from 'path';
import express from 'express';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import config from './webpack.config';
const app = express(),
DIST_DIR = path.join(__dirname, 'client'),
HTML_FILE = path.join(DIST_DIR, 'index.html'),
compiler = webpack(config),
isDevelopment = process.env.NODE_ENV === 'development';
if (isDevelopment) {
app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
}));
app.use(webpackHotMiddleware(compiler));
} else {
app.use(express.static(DIST_DIR));
}
app.get('/', (req, res) => res.sendFile(HTML_FILE));
app.get('*', (req, res) => res.redirect(301, '/'));
app.listen(process.env.PORT || 4200);