-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathstaticServer.js
More file actions
35 lines (28 loc) · 834 Bytes
/
staticServer.js
File metadata and controls
35 lines (28 loc) · 834 Bytes
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
/* eslint-disable no-console */
const express = require('express');
const path = require('path');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
const proxy = {
'/api': {
target: 'http://127.0.0.1:8000',
changeOrigin: true,
},
};
const port = parseInt(process.env.PORT, 10) || 3001;
//
// app.use('/api/events/list', (req, res) => {
// console.log('test');
//
// res.status(200).json([]).send();
// });
if (proxy) {
Object.keys(proxy).forEach(function (context) {
app.use(createProxyMiddleware(context, proxy[context]));
});
}
app.use(express.static('build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'build', 'index.html'));
});
app.listen(port, () => console.log(`server has been started on ${port}`));