/** Serve the game state of any valid game id. */ app.get('/:gameid/game', (req, res) => { const userid = getUserId(req, res); const game = games[parseInt(req.params['gameid'])] if (game == undefined) { res.status(404).json("no such game"); } else { if (isWaiting(game, userid)) { // Game is still waiting for a second player - join it! console.log(`Game ${game.id} directly joined by ${userid}`) joinGame(game, userid) } res.json(toJson(game, userid)) } })