X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lmno.js;h=abb1f2057c2582aad12d87e05ac732113583e0bb;hb=a5dd0c5e612311132f053b71f32a1fe94e5819d3;hp=c990cac3a290be99bf16d57f7d581442970bf4f4;hpb=70a137f52f6753491838515016489cab1347261b;p=empires-server diff --git a/lmno.js b/lmno.js index c990cac..abb1f20 100644 --- a/lmno.js +++ b/lmno.js @@ -48,6 +48,7 @@ nunjucks.configure("templates", { /* Load each of our game mini-apps. */ var empires = require("./empires"); +var tictactoe = require("./tictactoe"); class LMNO { constructor() { @@ -55,7 +56,7 @@ class LMNO { } generate_id() { - return [null,null,null,null].map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join(''); + return Array(4).fill(null).map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join(''); } create_game(engine) { @@ -136,14 +137,15 @@ app.get('/[a-zA-Z0-9]{4}', (request, response) => { }); /* LMNO middleware to lookup the game. */ -app.use('/empires/:game_id([a-zA-Z0-9]{4})', (request, response, next) => { +app.use('/:engine([^/]+)/:game_id([a-zA-Z0-9]{4})', (request, response, next) => { + const engine = request.params.engine; const game_id = request.params.game_id; const canon_id = lmno_canonize(game_id); /* Redirect user to page with the canonical ID in it. */ if (game_id !== canon_id) { - const new_url = request.originalUrl.replace("/empires/" + game_id, - "/empires/" + canon_id); + const new_url = request.originalUrl.replace(`/${engine}/${game_id}`, + `/${engine}/${canon_id}`); response.redirect(301, new_url); return; } @@ -239,6 +241,7 @@ app.get('/admin/', auth_admin, (request, response) => { /* Mount sub apps. only _after_ we have done all the middleware we need. */ app.use('/empires/[a-zA-Z0-9]{4}/', empires.app); +app.use('/tictactoe/[a-zA-Z0-9]{4}/', tictactoe.app); app.listen(4000, function () { console.log('LMNO server listening on localhost:4000');