-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (39 loc) · 1.12 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
/* global require process __dirname */
var express = require('express');
var path = require('path');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({
changeOrigin: true
});
var app = express();
var isProduction = process.env.NODE_ENV === 'production';
var port = isProduction ? process.env.PORT : 3000;
var publicPath = path.resolve(__dirname, 'dist');
// point to static assets
app.use(express.static(publicPath));
app.all('/proxy', (req, res) => {
res.send('here I am!');
});
app.all('/test', (req, res) => {
proxy.web(req, res, {
target: 'https://guitar-helper-cc2e6.firebaseio.com/',
});
});
// only run workflow when not in production
if (!isProduction) {
var bundle = require('./server/bundle.js');
bundle();
// proxy requests from 3000 -> dev-server
app.all('/*', function(req, res) {
proxy.web(req, res, {
target: 'http://localhost:8080/dist/'
});
});
}
// catch errors from proxy
proxy.on('error', function(e){
console.log('Could not connect to proxy, please try again...', e);
});
app.listen(port, () => {
console.log('Server running on port ' + port);
});