From: Carl Worth Date: Wed, 27 May 2020 17:06:23 +0000 (-0700) Subject: Use an express Router for each of the game-engine-specific sub-apps X-Git-Url: https://git.cworth.org/git?p=empires-server;a=commitdiff_plain;h=20ab7f84abd07b744d0c73f0dd54879ff884e534 Use an express Router for each of the game-engine-specific sub-apps This eliminates the redundant code that was otherwise required by using an entire app at the level of each game engine, (setting up cors, body-parser, nunjucks configuration, etc.). So this is much more pleasant, with less boilerplate and less code duplication. --- diff --git a/empires.js b/empires.js index 034ba42..c2ba106 100644 --- a/empires.js +++ b/empires.js @@ -1,18 +1,6 @@ const express = require("express"); -const cors = require("cors"); -const body_parser = require("body-parser"); -const path = require("path"); -const nunjucks = require("nunjucks"); - -const app = express(); -app.use(cors()); -app.use(body_parser.urlencoded({ extended: false })); -app.use(body_parser.json()); - -nunjucks.configure("templates", { - autoescape: true, - express: app -}); + +const app = express.Router(); const GameState = { JOIN: 1, diff --git a/tictactoe.js b/tictactoe.js index 82c5f7e..766c1e4 100644 --- a/tictactoe.js +++ b/tictactoe.js @@ -1,18 +1,6 @@ const express = require("express"); -const cors = require("cors"); -const body_parser = require("body-parser"); -const path = require("path"); -const nunjucks = require("nunjucks"); - -const app = express(); -app.use(cors()); -app.use(body_parser.urlencoded({ extended: false })); -app.use(body_parser.json()); - -nunjucks.configure("templates", { - autoescape: true, - express: app -}); + +const app = express.Router(); class TicTacToe { constructor() {