-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (37 loc) · 1.02 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
var path = require('path');
var express = require('express');
var pkg = require('./package');
var isProduction = (process.env.NODE_ENV === 'production');
var frontendPath = path.join(__dirname, 'samples/index.html');
var config = {
port: 8087
};
function startServer(config) {
var app = express();
if (!isProduction) {
var webpack = require('webpack');
var webpackConfig = require('./webpack.config');
var compiler = webpack(webpackConfig);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
}
app.get('*', function (req, res) {
if (req.accepts('html')) {
res.sendFile(frontendPath);
} else {
res.status(404);
res.end();
}
});
app.listen(config.port, '0.0.0.0', function (err) {
if (err) {
console.log(err);
return;
}
console.log(pkg.name + ' start server at port ' + config.port);
});
}
startServer(config);