-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (28 loc) · 838 Bytes
/
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
const express = require('express');
const cors = require('cors');
const path = require('path');
const app = express();
app.use(express.json())
const http = require('http').createServer(app);
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.resolve(__dirname, 'public')));
} else {
const corsOptions = {
origin: [
'http://127.0.0.1:8080',
'http://localhost:8080',
'http://127.0.0.1:3000',
'http://localhost:3000'
],
credentials: true,
};
app.use(cors(corsOptions));
}
const gameRoutes = require('./api/game/game.routes');
const { connectSockets } = require('./services/socket.service');
app.use('/api/game', gameRoutes);
connectSockets(http)
const port = process.env.PORT || 3030;
http.listen(port, () => {
console.log('Server is running on port: ' + port);
});