This repository was archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (34 loc) · 1.33 KB
/
server.js
File metadata and controls
39 lines (34 loc) · 1.33 KB
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
// server.js
const app = require("./app");
const mongoose = require('mongoose');
const SubmittedMission = require('./models/SubmittedMission');
const Team = require('./models/Team');
var server = require('http').createServer(app);
var io = require('socket.io')(server);
server.listen(process.env.PORT || 6969);
// Judge panel socket.io setup:
const submissionTicketSocket = io.of('/judge-tickets');
submissionTicketSocket.on('connection', socket =>{
console.log('submissionTicketSocket connected');
})
const leaderboardSocket = io.of('/leaderboard-scores')
leaderboardSocket.on('connection', socket => {
console.log('leaderboard socket connected')
})
const mongoURI = process.env.MONGO_URI || require("./config/secretKeys").mongoURI;
mongoose
.connect(mongoURI, { useNewUrlParser: true })
.then(() => {
console.log('MongoDB Connected');
const changeStream = SubmittedMission.watch([], {fullDocument : "updateLookup" });
changeStream.on('change',(change)=>{
console.log('some submissions have changed')
submissionTicketSocket.emit('submissionsChanged', change.fullDocument);
});
const leaderboardChangeStream = Team.watch([])
leaderboardChangeStream.on('change', (change) => {
leaderboardSocket.emit('scoresChanged', change.fullDocument)
})
})
.catch((err) => console.log(err));
mongoose.set('useNewUrlParser', true);