return db settings only to client, sanitize keys
This commit is contained in:
1 parent
91c2f7f0d5
commit
7a855ef47a
2 files changed
+13
-10
No files matched your search
@@ -11,16 +11,15 @@ class SettingsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAppSettings = async (req, res, next) => {
|
getAppSettings = async (req, res, next) => {
|
||||||
try {
|
const dbSettings = await this.settingsService.getDBSettings();
|
||||||
const settings = { ...(await this.settingsService.getSettings()) };
|
const sanitizedSettings = { ...dbSettings };
|
||||||
delete settings.jwtSecret;
|
if (typeof sanitizedSettings.pagespeedApiKey !== "undefined") {
|
||||||
return res.success({
|
sanitizedSettings.pagespeedApiKey = "********";
|
||||||
msg: this.stringService.getAppSettings,
|
|
||||||
data: settings,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(handleError(error, SERVICE_NAME, "getAppSettings"));
|
|
||||||
}
|
}
|
||||||
|
return res.success({
|
||||||
|
msg: this.stringService.getAppSettings,
|
||||||
|
data: sanitizedSettings,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
updateAppSettings = async (req, res, next) => {
|
updateAppSettings = async (req, res, next) => {
|
||||||
@@ -32,7 +31,6 @@ class SettingsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(req.body);
|
|
||||||
await this.db.updateAppSettings(req.body);
|
await this.db.updateAppSettings(req.body);
|
||||||
const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
|
const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
|
||||||
delete updatedSettings.jwtSecret;
|
delete updatedSettings.jwtSecret;
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ class SettingsService {
|
|||||||
}
|
}
|
||||||
return this.settings;
|
return this.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDBSettings() {
|
||||||
|
const settings = await this.appSettings.findOne({ singleton: true }).lean();
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SettingsService;
|
export default SettingsService;
|
||||||
Reference in new issue
Block a user