-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
34 lines (25 loc) · 840 Bytes
/
app.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
const express = require('express');
const app = express();
const server = require('http').Server(app);
const bodyParser = require('body-parser');
const lobby = require('./src/lobby.js');
// ============== CONFIG ===============
const PORT = 3000;
// =====================================
require('./src/connection_service').init(server, lobby);
app.use('/', express.static(__dirname));
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.get('/api/games', (req, res) => {
const games = lobby.getGames();
res.status(200).send(games);
});
app.post('/api/games', (req, res) => {
const isSuccess = lobby.createGame(req.body);
isSuccess ? res.sendStatus(200) : res.sendStatus(400);
});
server.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});