From: Carl Worth Date: Sat, 23 May 2020 02:29:33 +0000 (-0700) Subject: Convert rendering of login.html to use a nunjucks template X-Git-Url: https://git.cworth.org/git?p=empires-server;a=commitdiff_plain;h=d9ad319ff41cae1c0a9d2a771941be25c1208e3d Convert rendering of login.html to use a nunjucks template This new base.html template will allow us to avoid duplicating a bunch of boilerplate as we start adding additional HTML pages. Also, we pull the undisplay, add_message, lmno_login, and lmno_login_loaded functions in instead of including the static JavaScript file from /lmno.js. This makes things much more independent here, (rather than relying on JavaScript functions defined in a script file that is maintained in a separate git repository: lmno.games). --- diff --git a/lmno.js b/lmno.js index abcdba2..ff66a9b 100644 --- a/lmno.js +++ b/lmno.js @@ -4,6 +4,7 @@ const body_parser = require("body-parser"); const session = require("express-session"); const bcrypt = require("bcrypt"); const path = require("path"); +const nunjucks = require("nunjucks"); try { var lmno_config = require("./lmno-config.json"); @@ -40,6 +41,11 @@ app.use(session({ saveUninitialized: false })); +nunjucks.configure("templates", { + autoescape: true, + express: app +}); + /* Load each of our game mini-apps. */ var empires = require("./empires"); @@ -184,7 +190,7 @@ app.get('/login', (request, response) => { return; } - response.sendFile(path.join(__dirname, './login.html')); + response.render('login.html'); }); app.post('/login', async (request, response) => { diff --git a/login.html b/login.html deleted file mode 100644 index f78e679..0000000 --- a/login.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - LMNO: Login - - - - - - - - -
- -
-
- - -
-
- - -
- -
- - -
- -
- -
-
- -
- - diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..6895772 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,42 @@ + + + + + + + {{ title }} + + + + + + {% block head %} + {% endblock %} + + + + +
+ +
+
+ + {% block page %} + {% endblock %} + +
+ + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..5767316 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,57 @@ +{% extends "base.html" %} + +{% block head %} + +{% endblock %} + +{% block page %} + +
+
+ + +
+ +
+ + +
+ +
+ +
+
+{% endblock %}