From f0df78e6a9e5be52cd9dcd541eb752f0276f9d1a Mon Sep 17 00:00:00 2001 From: jomo Date: Wed, 14 Oct 2015 23:42:27 +0200 Subject: [PATCH] allow editing index html when debug_enabled = true --- config.example.js | 2 +- lib/routes/index.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config.example.js b/config.example.js index df972f5..25b273e 100644 --- a/config.example.js +++ b/config.example.js @@ -28,7 +28,7 @@ var config = { }, server: { http_timeout: 2000, // ms until connection to Mojang is dropped - debug_enabled: false, // enables logging.debug + debug_enabled: false, // enables logging.debug & editing index page log_time: true // set to false if you use an external logger that provides timestamps } }; diff --git a/lib/routes/index.js b/lib/routes/index.js index da20c4d..fc13275 100644 --- a/lib/routes/index.js +++ b/lib/routes/index.js @@ -1,12 +1,25 @@ +var logging = require("../logging"); var config = require("../../config"); var path = require("path"); var read = require("fs").readFileSync; var ejs = require("ejs"); -var str = read(path.join(__dirname, "..", "views", "index.html.ejs"), "utf-8"); -var index = ejs.compile(str); +var str; +var index; + +function compile() { + logging.log("Compiling index page"); + str = read(path.join(__dirname, "..", "views", "index.html.ejs"), "utf-8"); + index = ejs.compile(str); +} + +compile(); module.exports = function(req, callback) { + if (config.server.debug_enabled) { + // allow changes without reloading + compile(); + } var html = index({ title: "Crafatar", domain: "https://" + req.headers.host,