From e86a155ec28fd172552fb5642b78eb2c5bc2fb06 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 12 Nov 2017 20:24:21 +0200 Subject: [PATCH] Remove express-handlebars, read manifest.json to get theme-color --- client/index.html | 8 ++++---- package.json | 1 - src/helper.js | 4 ++++ src/server.js | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/client/index.html b/client/index.html index b22b180e..78051d25 100644 --- a/client/index.html +++ b/client/index.html @@ -9,23 +9,23 @@ - + The Lounge - + - + - + " data-transports="<%- JSON.stringify(transports) %>">
diff --git a/package.json b/package.json index 4a708b30..10b557a1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "colors": "1.1.2", "commander": "2.11.0", "express": "4.16.2", - "express-handlebars": "3.0.0", "fs-extra": "4.0.2", "irc-framework": "2.9.1", "ldapjs": "1.0.1", diff --git a/src/helper.js b/src/helper.js index 1f44d81e..0f65d085 100644 --- a/src/helper.js +++ b/src/helper.js @@ -78,6 +78,10 @@ function setHome(homePath) { log.warn(`${colors.bold("displayNetwork")} and ${colors.bold("lockNetwork")} are false, setting ${colors.bold("lockNetwork")} to true.`); } + // Load theme color from manifest.json + const manifest = require("../public/manifest.json"); + this.config.themeColor = manifest.theme_color; + // TODO: Remove in future release if (this.config.debug === true) { log.warn("debug option is now an object, see defaults file for more information."); diff --git a/src/server.js b/src/server.js index 34305c4b..f7497f0d 100644 --- a/src/server.js +++ b/src/server.js @@ -5,7 +5,6 @@ var pkg = require("../package.json"); var Client = require("./client"); var ClientManager = require("./clientManager"); var express = require("express"); -var expressHandlebars = require("express-handlebars"); var fs = require("fs"); var path = require("path"); var io = require("socket.io"); @@ -39,21 +38,14 @@ module.exports = function() { } var app = express() + .disable("x-powered-by") .use(allRequests) .use(index) .use(express.static("public")) .use("/storage/", express.static(Helper.getStoragePath(), { redirect: false, maxAge: 86400 * 1000, - })) - .engine("html", expressHandlebars({ - extname: ".html", - helpers: { - tojson: (c) => JSON.stringify(c), - }, - })) - .set("view engine", "html") - .set("views", path.join(__dirname, "..", "public")); + })); app.get("/themes/:theme.css", (req, res) => { const themeName = req.params.theme; @@ -221,9 +213,17 @@ function index(req, res, next) { policies.unshift("block-all-mixed-content"); } + res.setHeader("Content-Type", "text/html"); res.setHeader("Content-Security-Policy", policies.join("; ")); res.setHeader("Referrer-Policy", "no-referrer"); - res.render("index", Helper.config); + + return fs.readFile(path.join(__dirname, "..", "public", "index.html"), "utf-8", (err, file) => { + if (err) { + throw err; + } + + res.send(_.template(file)(Helper.config)); + }); } function initializeClient(socket, client, token, lastMessage) {