From 9b0f7a03b71f9fc5259f7ef9159725d9841b20a2 Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Sat, 1 Sep 2018 15:48:29 -0700 Subject: [PATCH] Handle settings changes without restart Prior to this change, edited settings on the /admin/settings page required a restart for the edit to take effect. This even causes the settings page itself to not reflect the updated settings once you navigate away from it or refresh. This change triggers the config to reload when the settings are modified, which causes the impacted templates to be recomputed. --- app.js | 9 +++++++++ routes/admin.js | 1 + 2 files changed, 10 insertions(+) diff --git a/app.js b/app.js index d831e44..815f28d 100644 --- a/app.js +++ b/app.js @@ -249,6 +249,15 @@ app.use((req, res, next) => { next(); }); +// update config when modified +app.use((req, res, next) => { + next(); + if (res.configDirty) { + config = common.getConfig(); + app.config = config; + } +}); + // Ran on all routes app.use((req, res, next) => { res.setHeader('Cache-Control', 'no-cache, no-store'); diff --git a/routes/admin.js b/routes/admin.js index d487bbb..6fedb4b 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -171,6 +171,7 @@ router.post('/admin/settings/update', common.restrict, common.checkAccess, (req, let result = common.updateConfig(req.body); if(result === true){ res.status(200).json({message: 'Settings successfully updated'}); + res.configDirty = true; return; } res.status(400).json({message: 'Permission denied'});