-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (36 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
33
34
35
36
37
38
39
40
41
42
43
44
45
const express = require('express');
const http = require('http');
const socketio = require('socket.io');
const config = require('config');
const app = express();
const path = require('path');
const server = http.createServer(app);
const io = socketio(server, {
cors: {
origin: '*',
},
});
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
});
app.use(express.static(path.join(__dirname, 'client/build')));
require('./startup/morgan')(app);
require('./startup/cors')(app);
require('./startup/db')(app);
require('./startup/routes')(app);
require('./WsRoute/index')(io);
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build/index.html'), function (err) {
if (err) {
res.status(500).send(err);
}
});
});
// Run when client connects
const port = process.env.PORT || config.get('port');
server.listen(port, () => console.log(`Listening on port ${port}...`));
process.on('uncaughtException', function (err, req, res, next) {
console.log('Node Server startup Error', err);
});
module.exports = server;