From d04124365041fb3d9606a0aa56b49a2147565038 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 25 May 2020 20:36:09 -0700 Subject: [PATCH] Add the barest template of an implementation of a tictactoe game This supports only the ability to select a nickname (which is provided by lmno.js), and then the serving of minimal HTML into which the tictactoe React cient can render itself. There is not yet here any implementation of API endpoints specific to the tictactoe game. Those will have to come later. (So, for now, each player that joins a game of Tic Tac Toe will have an independent game without any communication between them.) --- lmno.js | 2 ++ templates/tictactoe-game.html | 20 ++++++++++++++++++++ tictactoe.js | 26 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 templates/tictactoe-game.html create mode 100644 tictactoe.js diff --git a/lmno.js b/lmno.js index 61c7f5c..8e84473 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() { @@ -240,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'); diff --git a/templates/tictactoe-game.html b/templates/tictactoe-game.html new file mode 100644 index 0000000..f80ebf4 --- /dev/null +++ b/templates/tictactoe-game.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block head %} + + + + + +{% endblock %} + +{% block page %} +

Tic Tac Toe

+ +

+ Just the classic game. +

+ +
+ +{% endblock %} diff --git a/tictactoe.js b/tictactoe.js new file mode 100644 index 0000000..18fe342 --- /dev/null +++ b/tictactoe.js @@ -0,0 +1,26 @@ +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 +}); + +app.get('/', (request, response) => { + const game = request.game; + + if (! request.session.nickname) + response.render('choose-nickname.html', { game_name: "Tic Tac Toe" }); + else + response.render('tictactoe-game.html'); +}); + +exports.app = app; -- 2.43.0