X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lmno.js;h=65c317d05f37bb1b964781dd84b1b6d0f3b0f1ab;hb=e26d357ee7d6e689d098889de66d1c8c40482544;hp=64a106bf9a492f0475c5e6a9800a306b0c5bfcdb;hpb=fb0b1540096a2014db71c374d3147d6c2143f491;p=empires-server diff --git a/lmno.js b/lmno.js index 64a106b..65c317d 100644 --- a/lmno.js +++ b/lmno.js @@ -1,9 +1,35 @@ const express = require("express"); const cors = require("cors"); const body_parser = require("body-parser"); +const session = require("express-session"); + +try { + var lmno_config = require("./lmno-config.json"); +} catch (err) { + config_usage(); + process.exit(1); +} + +function config_usage() { + console.log(`Error: Refusing to run without configuration. + +Please create a file named lmno-config.json that looks as follows: + +{ + "session_secret": ""; +} + +Note: Don't use the exact text above, but instead replace the string +with what it describes: a long string of random characters.`); +} const app = express(); app.use(cors()); +app.use(session({ + secret: lmno_config.session_secret, + resave: false, + saveUninitialized: false +})); /* Load each of our game mini-apps. */ var empires = require("./empires"); @@ -107,11 +133,15 @@ app.use('/empires/:game_id([a-zA-Z0-9]{4})', (request, response, next) => { return; } - request.game = lmno.ids[game_id].game; - if (request.game === undefined) { + /* See if there is any game with this ID. */ + const game = lmno.ids[game_id]; + if (game === undefined) { response.sendStatus(404); return; } + + /* Stash the game onto the request to be used by the game-specific code. */ + request.game = game.game; next(); });