Skip to content

Commit 7a855ef

Browse files
committed
return db settings only to client, sanitize keys
1 parent 91c2f7f commit 7a855ef

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

server/controllers/settingsController.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ class SettingsController {
1111
}
1212

1313
getAppSettings = async (req, res, next) => {
14-
try {
15-
const settings = { ...(await this.settingsService.getSettings()) };
16-
delete settings.jwtSecret;
17-
return res.success({
18-
msg: this.stringService.getAppSettings,
19-
data: settings,
20-
});
21-
} catch (error) {
22-
next(handleError(error, SERVICE_NAME, "getAppSettings"));
14+
const dbSettings = await this.settingsService.getDBSettings();
15+
const sanitizedSettings = { ...dbSettings };
16+
if (typeof sanitizedSettings.pagespeedApiKey !== "undefined") {
17+
sanitizedSettings.pagespeedApiKey = "********";
2318
}
19+
return res.success({
20+
msg: this.stringService.getAppSettings,
21+
data: sanitizedSettings,
22+
});
2423
};
2524

2625
updateAppSettings = async (req, res, next) => {
@@ -32,7 +31,6 @@ class SettingsController {
3231
}
3332

3433
try {
35-
console.log(req.body);
3634
await this.db.updateAppSettings(req.body);
3735
const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
3836
delete updatedSettings.jwtSecret;

server/service/settingsService.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class SettingsService {
5454
}
5555
return this.settings;
5656
}
57+
58+
async getDBSettings() {
59+
const settings = await this.appSettings.findOne({ singleton: true }).lean();
60+
return settings;
61+
}
5762
}
5863

5964
export default SettingsService;

0 commit comments

Comments
 (0)