-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (39 loc) · 1.57 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
const express = require('express');
const path = require('path');
const port = (process.env.PORT || 8080);
const app = express();
const publicPathS = express.static(path.join(__dirname, 'public'), { redirect : false });
if (process.env.NODE_ENV !== 'production') {
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const DashboardPlugin = require('webpack-dashboard/plugin');
const config = require('./webpack.dev.config.js');
const compiler = webpack(config);
compiler.apply(new DashboardPlugin());
app.use(webpackHotMiddleware(compiler));
app.use(webpackDevMiddleware(compiler, {
noInfo : true,
stats : {
colors : true
},
publicPath : config.output.publicPath
}));
const indexPathD = path.join(__dirname, 'index.html');
const publicPath = express.static(path.join(__dirname, 'public'));
app.use('/public', publicPath);
app.get('/', function (_, res) { res.sendFile(indexPathD) });
app.get('*', function (_, res) { res.sendFile(indexPathD) });
} else {
const indexPath = path.join(__dirname, 'public/index.html');
app.use(publicPathS);
app.get('/', function (_, res) { res.sendFile(indexPath) });
app.get('*', function (_, res) { res.sendFile(indexPath) });
}
app.listen(port, function(err) {
if (err) {
console.log(err);
return;
}
});
console.log(`Listening at http://localhost:${port}`);