this.games[id] = {
id: id,
- engine: engine.name,
game: game
};
response.sendStatus(404);
return;
}
- response.redirect(301, `/${game.engine}/${game.id}/`);
+ response.redirect(301, `/${game.game.meta.identifier}/${game.id}/`);
});
/* LMNO middleware to lookup the game. */
/* 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.router);
+
+ /* Add routes that are common to all games. */
+ engine.router.get('/', (request, response) => {
+ const game = request.game;
+
+ if (! request.session.nickname)
+ response.render('choose-nickname.html', { game_name: game.meta.name });
+ else
+ response.render(`${game.meta.identifier}-game.html`);
+ });
+
+ /* And mount the whole router at the path for the game. */
+ app.use(`/${engine.Game.meta.identifier}/[a-zA-Z0-9]{4}/`, engine.router);
}
app.listen(4000, function () {