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) => {
|
||||
try {
|
||||
const settings = { ...(await this.settingsService.getSettings()) };
|
||||
delete settings.jwtSecret;
|
||||
return res.success({
|
||||
msg: this.stringService.getAppSettings,
|
||||
data: settings,
|
||||
});
|
||||
} catch (error) {
|
||||
next(handleError(error, SERVICE_NAME, "getAppSettings"));
|
||||
const dbSettings = await this.settingsService.getDBSettings();
|
||||
const sanitizedSettings = { ...dbSettings };
|
||||
if (typeof sanitizedSettings.pagespeedApiKey !== "undefined") {
|
||||
sanitizedSettings.pagespeedApiKey = "********";
|
||||
}
|
||||
return res.success({
|
||||
msg: this.stringService.getAppSettings,
|
||||
data: sanitizedSettings,
|
||||
});
|
||||
};
|
||||
|
||||
updateAppSettings = async (req, res, next) => {
|
||||
@@ -32,7 +31,6 @@ class SettingsController {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(req.body);
|
||||
await this.db.updateAppSettings(req.body);
|
||||
const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
|
||||
delete updatedSettings.jwtSecret;
|
||||
|
||||
@@ -54,6 +54,11 @@ class SettingsService {
|
||||
}
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
async getDBSettings() {
|
||||
const settings = await this.appSettings.findOne({ singleton: true }).lean();
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
export default SettingsService;
|
||||
Reference in new issue
Block a user