return db settings only to client, sanitize keys

This commit is contained in:
Alex Holliday committed 2025-05-08 13:24:24 -07:00
1 parent 91c2f7f0d5
commit 7a855ef47a
2 files changed
+13 -10

No files matched your search

+8 -10
View File
@@ -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;
+5
View File
@@ -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;