-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
42 lines (35 loc) · 1.27 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
'use strict';
const express = require('express');
const proxy = require('express-http-proxy');
const path = require('path');
const PORT = 8000;
const HOST = '0.0.0.0';
const API_URL = process.env.API_HOST;
console.log(`API proxy set to ${API_URL}`);
const app = express();
// API proxy
app.use('/api', proxy(API_URL, {
proxyReqPathResolver: function(req) {
var parts = req.url.split('?');
var queryString = parts[1];
var updatedPath = parts[0].replace(/v1/, 'api/v1');
return updatedPath + (queryString ? '?' + queryString : '');
},
proxyReqOptDecorator: function(proxyReqOpts, srcReq) {
proxyReqOpts.headers['X-Forwarded-Proto'] = srcReq.protocol;
proxyReqOpts.headers['X-Real-IP'] = srcReq.ip;
return proxyReqOpts;
},
proxyErrorHandler: function(err, res, next) {
console.log(`API Proxy encountered error: ${err.code} - ${res}`);
next(err);
}
}));
// Static resources
app.get('/service-worker.js', function (req, res) {
res.set('Cache-Control', 'no-store, no-cache, must-revalidate, private')
res.sendFile(__dirname + '/build/service-worker.js')
})
app.use(express.static(path.join(__dirname + "/build", '/')));
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);