-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
38 lines (29 loc) · 1023 Bytes
/
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
var express = require('express');
var httpProxy = require('http-proxy');
var app = express();
var proxy = httpProxy.createProxyServer();
var port = isProduction ? process.env.PORT : 3000;
var isProduction = process.env.NODE_ENV === 'production';
app.use(express.static('public'));
app.use('/assets', express.static('assets'));
// We only want to run the workflow when not in production
if (!isProduction) {
// We require the bundler inside the if block because
// it is only needed in a development environment. Later
// you will see why this is a good idea
var bundle = require('./server/bundle.js');
bundle();
// Any requests to localhost:3000/build is proxied
// to webpack-dev-server
app.all('/build/*', function (req, res) {
proxy.web(req, res, {
target: 'http://localhost:8080'
});
});
}
proxy.on('error', function(e) {
console.log('Could not connect to proxy, please try again...');
});
app.listen(port, function () {
console.log('Server running on port ' + port);
});