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.
master
Ben Burns 2018-09-01 15:48:29 -07:00 committed by Mark Moffat
parent 70127ee0bc
commit 9b0f7a03b7
2 changed files with 10 additions and 0 deletions

9
app.js
View File

@ -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');

View File

@ -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'});