-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
57 lines (52 loc) · 1.59 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
46
47
48
49
50
51
52
53
54
55
56
57
const express = require('express');
const { updateScore, fetchScore } = require('./src/score/score');
const bodyParser = require('body-parser');
const app = express();
const jsonParser = bodyParser.json();
app.post('/update/:matchId', jsonParser, (req, res) => {
const matchId = req.params.matchId;
if (matchId.length < 3) {
return res
.status(400)
.json({ message: 'Match ID must be string with at least three characters' });
}
return updateScore(matchId, {
pointsA: req.body.pointsA,
pointsB: req.body.pointsB,
setA: req.body.setA,
setB: req.body.setB,
nameA: req.body.nameA,
nameB: req.body.nameB,
logoA: req.body.logoA,
logoB: req.body.logoB,
colorA: req.body.colorA,
colorB: req.body.colorB,
}).then(() => res.json({ message: 'Data received.' }))
.catch(res.status(500).json({ message: 'Error updating score.' }));
});
app.get('/scores/:matchId', (req, res) => {
const matchId = req.params.matchId;
if (matchId.length < 3) {
return res
.status(400)
.json({ message: 'Match ID must be string with at least three characters' });
}
return fetchScore(matchId).then(data =>
res.json({
pointsA: data.pointsA,
pointsB: data.pointsB,
setA: data.setA,
setB: data.setB,
nameA: data.nameA,
nameB: data.nameB,
logoA: data.logoA,
logoB: data.logoB,
colorA: data.colorA,
colorB: data.colorB,
}),
);
});
app.use(express.static('public'));
app.listen(process.env.PORT || 3000, () => {
console.log(`OBS Scoreboard Plugin listening on port ${process.env.PORT || 3000}`);
});