-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
32 lines (27 loc) · 936 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
//Install express server
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const path = require('path');
const APP = express();
const HOST = 'https://oworms-api.herokuapp.com';
const PORT = 8080;
// serve only static files from dist directory
APP.use(express.static(__dirname + '/dist/oworms'));
// proxy conf for prod
APP.use('/api', createProxyMiddleware({
target: HOST,
secure: false,
changeOrigin: true,
pathRewrite: {
[`^/api`]: '',
},
}));
// final catch-all route to index.html defined last
// send requests to dist folder and serve index.html (SPA)
APP.get('/*', function (req, res) {
res.sendFile(path.join(__dirname + '/dist/oworms/index.html'));
});
// Start the app by listening on the default Heroku port
APP.listen(process.env.PORT || PORT, () => {
console.log(`Starting Proxy at ${ HOST }:${ process.env.PORT || PORT }`);
});