-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.js
38 lines (33 loc) · 890 Bytes
/
server.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
const express = require('express');
const http = require('http');
const app = express();
const port = parseInt((process.env.PORT || 1337), 10);
const Player = require('./Player');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.post('/', (req, res) => {
const { action, game_state } = req.body;
switch (action) {
case 'version':
res.send(Player.VERSION);
break;
case 'bet_request':
Player.betRequest(JSON.parse(game_state), function(bet) {
res.json(bet);
});
break;
case 'showdown':
Player.showdown(JSON.parse(game_state));
res.send('Ok');
break;
case 'check':
res.send('Ok');
break;
default:
res.send('Unknown action');
}
});
const server = http.createServer(app);
server.listen(port, () => {
console.log(`Server listening at: localhost:${port}`);
});