-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
49 lines (40 loc) · 1.17 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
var path = require('path');
var express = require('express');
var app = express();
var isDev = process.env.NODE_ENV !== 'production';
// Load static resources
app.use(express.static(path.join(__dirname, 'public')));
// If in development
if (isDev) {
var webpack = require('webpack');
var webpackMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var config = require('./webpack.dev.js');
var compiler = webpack(config);
var middleware = webpackMiddleware(compiler, {
publicPath: config.output.publicPath,
noInfo: true,
quiet: false,
lazy: false,
watchOptions: {
aggregateTimeout: 300,
poll: true
},
stats: {
colors: true,
}
});
app.use(middleware);
app.use(webpackHotMiddleware(compiler));
} else {
app.use(express.static(path.join(__dirname, 'dist')));
}
// Fallback to index.html for all other requests
app.get('*', function(req,res){
res.sendFile(__dirname + '/public/index.html');
});
var port = isDev ? 8080 : process.env.PORT;
app.listen(port, '0.0.0.0', function onStart(err) {
if (err) console.log(err);
console.info('Listening on port ' + port);
});