]> git.cworth.org Git - empires-server/commitdiff
Rename "app" to "router" within each game engine
authorCarl Worth <cworth@cworth.org>
Wed, 27 May 2020 17:10:02 +0000 (10:10 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 27 May 2020 17:10:02 +0000 (10:10 -0700)
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
lmno.js
tictactoe.js

index c2ba106a641fc2359ddcb37e51afa34bce415b9b..7907ce0c80a7711d4c92044f7391298156c2a664 100644 (file)
@@ -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 7c374eff600b32e5da09eedf9657b2732bb63114..175fe6300472cd914c562d7271131d8024cf6281 100644 (file)
--- 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 () {
index 766c1e4ed569cf9d2efb52bae9e7d70ffc6ce6fa..a38cea0e807f02d4e1aea2448263c7a2ebdbae1e 100644 (file)
@@ -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;