-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
45 lines (34 loc) · 1.2 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
'use strict';
require('babel-core/register');
let path = require('path');
let webpack = require('webpack');
if (process.env.NODE_ENV == 'production') {
// Production mode uses an Express server
let express = require('express');
let httpProxy = require('http-proxy');
let app = express();
let static_path = path.join(__dirname, 'build');
let serverPort = process.env.PORT || 8080;
app
.use(express.static(static_path))
.get('/', function (req, res) {
res.sendFile('index.html', {
root: static_path
});
})
.listen(serverPort, function (err) {
if (err) console.error(err);
console.log(`[NODE] * Listening at localhost:${ serverPort } (production)`);
});
} else {
// Development mode uses a webpack-dev-server
let config = require(path.resolve(__dirname, 'webpack.config.babel')).default;
let WebpackDevServer = require('webpack-dev-server');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
proxy: config.devServer.proxy
}).listen(config.devServer.port, 'localhost', function (err, result) {
if (err) console.error(err);
console.log('[NODE] * Listening at localhost:9000 (development)');
});
}