From eec2fd5c7db6f39a9994fa620619ebf005d26064 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 27 May 2020 10:10:02 -0700 Subject: [PATCH] Rename "app" to "router" within each game engine This is a more suitable name now that each of these objects is actually an express router and not a full-fledged express app. --- empires.js | 36 ++++++++++++++++++------------------ lmno.js | 2 +- tictactoe.js | 10 +++++----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/empires.js b/empires.js index c2ba106..7907ce0 100644 --- a/empires.js +++ b/empires.js @@ -1,6 +1,6 @@ const express = require("express"); -const app = express.Router(); +const router = express.Router(); const GameState = { JOIN: 1, @@ -285,14 +285,14 @@ function handle_events(request, response) { }); } -app.get('/', (request, response) => { +router.get('/', (request, response) => { if (! request.session.nickname) response.render('choose-nickname.html', { game_name: "Empires" }); else response.render('empires-game.html'); }); -app.post('/spectator', (request, response) => { +router.post('/spectator', (request, response) => { const game = request.game; var name = request.session.nickname; @@ -304,13 +304,13 @@ app.post('/spectator', (request, response) => { response.send(JSON.stringify(id)); }); -app.delete('/spectator/:id', (request, response) => { +router.delete('/spectator/:id', (request, response) => { const game = request.game; game.remove_spectator(parseInt(request.params.id)); response.send(); }); -app.post('/register', (request, response) => { +router.post('/register', (request, response) => { const game = request.game; var name = request.session.nickname;; @@ -322,70 +322,70 @@ app.post('/register', (request, response) => { response.send(); }); -app.post('/deregister/:id', (request, response) => { +router.post('/deregister/:id', (request, response) => { const game = request.game; game.remove_player(parseInt(request.params.id)); response.send(); }); -app.post('/reveal', (request, response) => { +router.post('/reveal', (request, response) => { const game = request.game; game.reveal(); response.send(); }); -app.post('/start', (request, response) => { +router.post('/start', (request, response) => { const game = request.game; game.start(); response.send(); }); -app.post('/reset', (request, response) => { +router.post('/reset', (request, response) => { const game = request.game; game.reset(); response.send(); }); -app.post('/capture/:captor/:captee', (request, response) => { +router.post('/capture/:captor/:captee', (request, response) => { const game = request.game; game.capture(parseInt(request.params.captor), parseInt(request.params.captee)); response.send(); }); -app.post('/liberate/:id', (request, response) => { +router.post('/liberate/:id', (request, response) => { const game = request.game; game.liberate(parseInt(request.params.id)); response.send(); }); -app.post('/restart', (request, response) => { +router.post('/restart', (request, response) => { const game = request.game; game.restart(parseInt(request.params.id)); response.send(); }); -app.get('/characters', (request, response) => { +router.get('/characters', (request, response) => { const game = request.game; response.send(game.characters); }); -app.get('/empires', (request, response) => { +router.get('/empires', (request, response) => { const game = request.game; response.send(game.empires); }); -app.get('/spectators', (request, response) => { +router.get('/spectators', (request, response) => { const game = request.game; response.send(game.spectators); }); -app.get('/players', (request, response) => { +router.get('/players', (request, response) => { const game = request.game; response.send(game.players); }); -app.get('/events', handle_events); +router.get('/events', handle_events); -exports.app = app; +exports.router = router; exports.name = "empires"; exports.Game = Game; diff --git a/lmno.js b/lmno.js index 7c374ef..175fe63 100644 --- a/lmno.js +++ b/lmno.js @@ -251,7 +251,7 @@ app.get('/admin/', auth_admin, (request, response) => { /* Mount sub apps. only _after_ we have done all the middleware we need. */ for (let key in engines) { const engine = engines[key]; - app.use(`/${engine.name}/[a-zA-Z0-9]{4}/`, engine.app); + app.use(`/${engine.name}/[a-zA-Z0-9]{4}/`, engine.router); } app.listen(4000, function () { diff --git a/tictactoe.js b/tictactoe.js index 766c1e4..a38cea0 100644 --- a/tictactoe.js +++ b/tictactoe.js @@ -1,6 +1,6 @@ const express = require("express"); -const app = express.Router(); +const router = express.Router(); class TicTacToe { constructor() { @@ -54,7 +54,7 @@ class TicTacToe { } } -app.get('/', (request, response) => { +router.get('/', (request, response) => { const game = request.game; if (! request.session.nickname) @@ -63,7 +63,7 @@ app.get('/', (request, response) => { response.render('tictactoe-game.html'); }); -app.post('/move', (request, response) => { +router.post('/move', (request, response) => { const game = request.game; const square = request.body.square; @@ -79,7 +79,7 @@ app.post('/move', (request, response) => { game.broadcast_move(square); }); -app.get('/events', (request, response) => { +router.get('/events', (request, response) => { const game = request.game; /* These headers will keep the connection open so we can stream events. */ @@ -99,6 +99,6 @@ app.get('/events', (request, response) => { }); }); -exports.app = app; +exports.router = router; exports.name = "tictactoe"; exports.Game = TicTacToe; -- 2.43.0