-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
32 lines (29 loc) · 1.08 KB
/
index.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
const express = require('express');
const proxy = require('http-proxy-middleware');
const socketEvents = require('./server/socketEvents');
const app = express();
if (process.env.NODE_ENV === 'production') {
// Change the cwd to server to mimic running directly
process.chdir('server');
// Only require inside the if block so we don't run the server code twice
// in development
const runServer = require('./server').runServer;
// Just run the server
runServer(process.env.PORT || 8080);
}
else {
// Proxy everything through to Create React App dev server
app.use(proxy('http://localhost:3000/', {
logLevel: 'warn', // Keep the logs clean
ws: true, // Proxy websockets too
router: {
// Anything to /api goes to our backend
'localhost:8080/api': 'http://localhost:3001'
}
}));
// Activate socket events at proxy server lvl in development
const server = require('http').createServer(app);
server.listen(process.env.PORT || 8080);
const io = require('socket.io')(server);
socketEvents(io);
}