-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathapp.js
31 lines (25 loc) · 987 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
const express = require('express')
const http = require('http')
const socketio = require('socket.io')
const gameLogic = require('./game-logic')
const app = express()
/**
* Backend flow:
* - check to see if the game ID encoded in the URL belongs to a valid game session in progress.
* - if yes, join the client to that game.
* - else, create a new game instance.
* - '/' path should lead to a new game instance.
* - '/game/:gameid' path should first search for a game instance, then join it. Otherwise, throw 404 error.
*/
const server = http.createServer(app)
const io = socketio(server)
// get the gameID encoded in the URL.
// check to see if that gameID matches with all the games currently in session.
// join the existing game session.
// create a new session.
// run when client connects
io.on('connection', client => {
gameLogic.initializeGame(io, client)
})
// usually this is where we try to connect to our DB.
server.listen(process.env.PORT || 8000)